0% found this document useful (0 votes)
54 views8 pages

Java Questions

1) The document contains questions about Java inheritance and polymorphism. 2) For the first question, the output would be "B" because class two overrides the myMethod() method from class one to return "B" instead of "A". 3) For invoking a method from the parent most class, the answer is C) Super.super.test() since it allows calling the test() method defined in class C without creating an instance of C.

Uploaded by

akragnarock
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
Download as ppt, pdf, or txt
0% found this document useful (0 votes)
54 views8 pages

Java Questions

1) The document contains questions about Java inheritance and polymorphism. 2) For the first question, the output would be "B" because class two overrides the myMethod() method from class one to return "B" instead of "A". 3) For invoking a method from the parent most class, the answer is C) Super.super.test() since it allows calling the test() method defined in class C without creating an instance of C.

Uploaded by

akragnarock
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1/ 8

Core Java Quiz 3

class one{
String s=myMethod();
String myMethod(){
return "A";
} }
class two extends one{
String myMethod(){
return "B";
} }
public class valan {
public static void main(String args[]){
one o=new two();
System.out.println(o.s);
} }
B

class A{
void display(){}
}
class B extends A {
//CODE1
}
Which of the below options can replace the
CODE1
a)void display()
b)Protected void display()
c)int display()
d)private display() A & B

Assume that class A extends class B, which
extends class C. Also all the three classes
implement the method test(). How can
a method in a class A invoke the test()
method defined in class C (without
creating a new instance of class C).
A) test();
B) Super.test();
C) Super.super.test();
D) C.test();
E) It is not possible
E
class demo1{}
class demo2 extends demo1{
int a;
}
public class valan {
public static void main(String args[]){
demo1 obj=new demo2();
System.out.println(obj.a);
}
}
Compile Time Error
class demo1{int a;}
class demo2 extends demo1{

}
public class valan {
public static void main(String args[]){
demo2 obj=new demo1();
System.out.println(obj.a);
}
}
Compile Time Error

class demo1{
int a=value();
int value(){
return 10;
}
}
class demo2 extends demo1{
int value(){
return 20;
}
}
public class valan {
public static void main(String args[]){
demo1 obj=new demo2();
System.out.println(obj.a);
}
}
20

Parent class extends Child class, which is
true about this:
a. Child c= new parent();
b. Parent c= new Child();
c. Parent c = new Object();
d. child c= new Object();
a

You might also like