Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Predict the output of the following program.class First{void display(){System.out.println("Inside First");}}class Second extends First{void display(){System.out.println("Inside Second");}}class Test{public static void main(String[] args){First obj1 = new First();Second obj2 = new Second();First ref;ref = obj1;ref.display();ref = obj2;ref.display();}}(A) Compilation error(B)Inside FirstInside Second(C)Inside FirstInside First(D) Runtime error

Answer»
2.

Predict the output of following Java programclass Test {int i;}class Main {public static void main(String args[]) {Test t = new Test();System.out.println(t.i);}}(A) garbage value(B) 0(C) compiler error(D) runtime error

Answer»
3.

Predict the output of following Java program.class demoClass{int a = 1;void func(){demo obj = new demo();obj.display();}class demo{int b = 2;void display(){System.out.println("\na = " + a);}}void get(){System.out.println("\nb = " + b);}}class Test{public static void main(String[] args){demoClass obj = new demoClass();obj.func();obj.get();}}(A)a = 1b = 2(B) Compilation error(C)b = 2a = 1

Answer»
4.

class demo{int a, b;demo(){a = 10;b = 20;}public void print(){System.out.println ("a = " + a + " b = " + b + "\n");}}class Test{public static void main(String[] args){demo obj1 = new demo();demo obj2 = obj1;obj1.a += 1;obj1.b += 1;System.out.println ("values of obj1 : ");obj1.print();System.out.println ("values of obj2 : ");obj2.print();}}(A) Compile error(B)values of obj1: a = 11 b = 21values of obj2: a = 11 b = 21(C)values of obj1: a = 11 b = 21values of obj2: a = 10 b = 20(D)values of obj1: a = 11 b = 20values of obj2: a = 10 b = 21(E) Run time error

Answer»