Sie sind auf Seite 1von 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

Das könnte Ihnen auch gefallen