Sail E0 Webinar

MCQs

Total Questions : 12 | Page 2 of 2 pages
Question 11. What is the output for the below code ?
class A{
private void printName(){
System.out.println("Value-A");
}
}
class B extends A{
public void printName(){
System.out.println("Name-B");
}
}
public class Test{
public static void main (String[] args){
B b = new B();
b.printName();
}
}
  1.    Value-A
  2.    Name-B
  3.    Value-A Name-B
  4.    Compilation fails - private methods can't be override
  5.    None of these
 Discuss Question
Answer: Option B. -> Name-B
Question 12. What is the output for the below code ?
class A{
public A(){
System.out.println("A");
}
public A(int i){
this();
System.out.println(i);
}
}
class B extends A{
public B(){
System.out.println("B");
}
public B(int i){
this();
System.out.println(i+3);
}
}
public class Test{
public static void main (String[] args){
new B(5);
}
}
  1.    A B 8
  2.    A 5 B 8
  3.    A B 5
  4.    B 8 A 5
  5.    None of these
 Discuss Question
Answer: Option A. -> A B 8

Latest Videos

Latest Test Papers