Programming in Java - Output Prediction

Programming in Java - Output Prediction

University

5 Qs

quiz-placeholder

Similar activities

Quiz on Java Operators

Quiz on Java Operators

University

7 Qs

Java Quiz 1

Java Quiz 1

University

10 Qs

Briefing Operator Java

Briefing Operator Java

University

10 Qs

Java Classes & Objects

Java Classes & Objects

University

5 Qs

Java Method Overloading

Java Method Overloading

University

6 Qs

CMP128 Java Ch. 05 Methods

CMP128 Java Ch. 05 Methods

University

10 Qs

Java Control Flow statements

Java Control Flow statements

University

10 Qs

Passaggio parametri

Passaggio parametri

University

9 Qs

Programming in Java - Output Prediction

Programming in Java - Output Prediction

Assessment

Quiz

Computers

University

Medium

Created by

Lakshmi Anand

Used 4+ times

FREE Resource

5 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Predict the output:

class Test {

protected int x=10, y=10;

}

class Main {

public static void main(String args[]) {

Test t = new Test();

System.out.println(t.x + " " + t.y);

}

}

Garbage Value

0 0

10 10

5 5

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Predict the output:

class Test {

private static int x;

public static void main(String args[]) {

System.out.println(fun());

}

static int fun() {

return ++x;

}

}

1

Error

0

Garbage Value

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Predict the output:

class Base {

public void Print()

{

System.out.println("Base");

}

}

class Derived extends Base {

public void Print()

{

System.out.println("Derived");

}

}

class Main {

public static void DoPrint(Base o)

{

o.Print();

}

public static void main(String[] args)

{

Base x = new Base();

Base y = new Derived();

Derived z = new Derived();

DoPrint(x);

DoPrint(y);

DoPrint(z);

}

}

Base

Derived

Base

Base

Derived

Derived

Derived

Base

Derived

Derived

Derived

Base

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Predict the output:

class Test {

int x = 10;

public static void main(String[] args)

{

Test t = new Test();

System.out.println(t.x);

}

}

1

0

10

11

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Predict the output:

class Base {

protected void foo() {}

}

class Derived extends Base {

void foo() {}

}

public class Main {

public static void main(String args[]) {

Derived d = new Derived();

d.foo();

}

}

Runtime Error

Garbage Value

0

Compile time Error