ExamVeda
Login
Home
This question belongs to Java Program Inheritence
Inheritence
?

Determine output:
class A{
      public void printValue(){
            System.out.println("Value-A");
      }
}
class B extends A{
      public void printNameB(){
            System.out.println("Name-B");
      }
}
class C extends A{
      public void printNameC(){
            System.out.println("Name-C");
      }
}

public class Test{
      public static void main (String[] args){
            B b = new B();
            C c = new C();
            newPrint(b);
            newPrint(c);
      }
      public static void newPrint(A a){
            a.printValue();
      }
 }

Answer & Solution
Correct Answer: Option B

Class B extended Class A therefore all methods of Class A will be available to class B except private methods. Class C has extended Class A therefore all methods of Class A will be available to class C except private methods.

Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.