What Will Be The Output Of The Following Java Codep Pre #620
What will be the output of the following Java code?</p> <pre><code class="language-java"> class Person { public void show() { System.out.println("None"); } } class College extends Person { public void show1() { System.out.println("I am in a College"); } } class School extends Person { public void show2() { System.out.println("I am in a School"); } } class University extends Person { public void show3() { System.out.println("I am in a University"); } } class HierarchicalInheritance { public static void main(String args[]) { School teacher = new School(); College student = new College(); University doctor = new University(); student.show(); student.show1(); teacher.show2(); doctor.show3(); } } </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 Types of Classes (Using Java) - Derived Class - Quiz No.1.
What will be the output of the following Java code?
class Person { public void show() { System.out.println("None"); } } class College extends Person { public void show1() { System.out.println("I am in a College"); } } class School extends Person { public void show2() { System.out.println("I am in a School"); } } class University extends Person { public void show3() { System.out.println("I am in a University"); } } class HierarchicalInheritance { public static void main(String args[]) { School teacher = new School(); College student = new College(); University doctor = new University(); student.show(); student.show1(); teacher.show2(); doctor.show3(); } }
None I am in a College I am in a School I am in a University
Compilation error
I am in a University I am in a School I am in a College None
None