What Will Be The Output Of The Following Java Codep Pre #862
What will be the output of the following Java code?</p> <pre><code class="language-java"> class A { protected void func() { System.out.println("Class A"); } } class B extends A { public void func() { System.out.println("Class B"); } } class C extends A { public void func() { System.out.println("Class C"); } } public class Display1 { public static void main(String[] args) { B obj1 = new B(); A obj2 = new C(); obj1.func(); obj2.func(); } }</code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs111 OOP Object Oriented Programming Java. It can also be found in gs gs111 Inheritance (Using Java) - Hierarchical Inheritance - Quiz No.1.
What will be the output of the following Java code?
class A { protected void func() { System.out.println("Class A"); } } class B extends A { public void func() { System.out.println("Class B"); } } class C extends A { public void func() { System.out.println("Class C"); } } public class Display1 { public static void main(String[] args) { B obj1 = new B(); A obj2 = new C(); obj1.func(); obj2.func(); } }
Class B Class A
Class B Class C
Class C Class A
Runtime Error