Question: Predict the output of the following programs from ( a ) to ( e ) . [ 5 * 2 = 1 0 marks ]
Predict the output of the following programs from a to e marks a interface Alpha int x ; void display; class Beta int x ; void display System.out.printx ; class Gamma extends Beta implements Alpha int x ; public void display System.out.printx super.x Alpha.x ; public class Main public static void mainString args Alpha objAlpha new Gamma; Beta objBeta new Gamma; Gamma objGamma new Gamma; objAlpha.display; objBeta.display; objGamma.display; b public class TestClass void tempint a double b System.out.printlnintdouble version"; void tempdouble a int b System.out.printlndoubleint version"; public static void mainString args TestClass test new TestClass; test.temp; test.temp; c class Outer int x ; int y; void display int x; int y; class Inner void show int y ; System.out.printlnx: x y: y; Inner inner new Inner; x ; Commented inner.show; public class Test public static void mainString args Outer outer new Outer; outer.display; d public class MyClass public int publicField; private String privateField; public void setPrivateFieldString value this.privateField value; public String getPrivateField return this.privateField; public void doSomething System.out.printlnThis is a public method."; protected void doSomethingElse System.out.printlnThis is a protected method."; public class Main public static void mainString args MyClass myClass new MyClass; myClass.doSomething; myClass.doSomethingElse; e public class Student public String name; private int age; public StudentString name, int age this.name name; this.age age; public void displayInfo System.out.printlnName: this.name; System.out.printlnAge: this.age; public void setAgeint age this.age age; public int getAge return this.age; public class Main public static void mainString args Student student new StudentJohn; student.displayInfo;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
