Programming in Java - Output Prediction

Programming in Java - Output Prediction

University

5 Qs

quiz-placeholder

Similar activities

Java Method Overloading

Java Method Overloading

University

6 Qs

Java array

Java array

11th Grade - University

6 Qs

JAVA array

JAVA array

12th Grade - University

10 Qs

DEBUG THE CODE

DEBUG THE CODE

University

10 Qs

Java Arrays

Java Arrays

University

10 Qs

OOP Quiz

OOP Quiz

University

10 Qs

Third Year Placement Training Revision Test

Third Year Placement Training Revision Test

University

10 Qs

Java Classes & Objects

Java Classes & Objects

University

5 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