MCQ Practice Single Best Answer Topic: Inheritance in Java MCQ

Q 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();
      }
}

Question ID
#2267
Subchapter
Inheritance in Java MCQ
Action
Choose one option below

Choose Your Answer

Click an option to check whether your answer is correct.

  • A Value-A
  • B Name-B
  • C Value-A Name-B
  • D Compilation fails - private methods can't be override
Correct Answer: B

Explanation

Name-B

Share This Question

Share this MCQ with your friends or study group.