Programming in Java - Output Prediction

Programming in Java - Output Prediction

University

5 Qs

quiz-placeholder

Similar activities

Trắc nghiệm kiến thức Java Core - Phần II

Trắc nghiệm kiến thức Java Core - Phần II

University

9 Qs

Java Classes

Java Classes

12th Grade - University

10 Qs

Thread Priorities

Thread Priorities

University

10 Qs

Java Class

Java Class

University

10 Qs

Inheritance and polymorphism

Inheritance and polymorphism

University

6 Qs

Basic bioinformatics

Basic bioinformatics

University

10 Qs

Java Quiz 1

Java Quiz 1

University

10 Qs

Writing Classes in Java

Writing Classes in Java

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