1

Determine output: class A{ public void printName(){ System.out.println("Name-A"); } } class B extends A{ public void printName(){ System.out.println("Name-B"); } } class C extends A{ public void printName(){ System.out.println("Name-C"); } } public class Test{ public static void main (String[] args){ B b = new B(); C c = new C(); b = c; newPrint(b); } public static void newPrint(A a){ a.printName(); } }

Correct Answer: Compilation fails due to an error on lines 5

Make the most of this question

This page focuses on one JAVA MCQs question from Programming. After checking the answer, return to the topic list to practice more or run a timed set.

JAVA MCQs MCQ: Determine output: class A{ public void printName(){ System.out.println("Name-A"); } } class B extends A{ public void printName(){ System.out.println("Name-B"); } } class C extends A{ public void printName(){ System.out.println("Name-C"); } } public class Test{ public static void main (String[] args){ B b = new B(); C c = new C(); b = c; newPrint(b); } public static void newPrint(A a){ a.printName(); } } | Extra Education