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).[5*2=10 marks] a) interface Alpha { int x =10; void display();} class Beta { int x =20; void display(){ System.out.print(x +""); }} class Gamma extends Beta implements Alpha { int x =30; public void display(){ System.out.print(x + super.x + Alpha.x +""); }} public class Main { public static void main(String[] args){ Alpha objAlpha = new Gamma(); Beta objBeta = new Gamma(); Gamma objGamma = new Gamma(); objAlpha.display(); objBeta.display(); objGamma.display(); }} b) public class TestClass { void temp(int a, double b){ System.out.println("int-double version"); } void temp(double a, int b){ System.out.println("double-int version"); } public static void main(String[] args){ TestClass test = new TestClass(); test.temp(10,20.5); test.temp(15.5,5); }} c) class Outer { int x =10; int y=67; void display(){ int x=13; int y=17; class Inner { void show(){ int y =15; System.out.println("x: "+ x +", y: "+ y); }} Inner inner = new Inner(); //x =14; Commented inner.show(); }} public class Test { public static void main(String[] args){ Outer outer = new Outer(); outer.display(); }} d) public class MyClass { public int publicField; private String privateField; public void setPrivateField(String value){ this.privateField = value; } public String getPrivateField(){ return this.privateField; } public void doSomething(){ System.out.println("This is a public method."); } protected void doSomethingElse(){ System.out.println("This is a protected method."); }} public class Main { public static void main(String[] args){ MyClass myClass = new MyClass(); myClass.doSomething(); myClass.doSomethingElse(); }} e) public class Student { public String name; private int age; public Student(String name, int age){ this.name = name; this.age = age; } public void displayInfo(){ System.out.println("Name: "+ this.name); System.out.println("Age: "+ this.age); } public void setAge(int age){ this.age = age; } public int getAge(){ return this.age; }} public class Main { public static void main(String[] args){ Student student = new Student("John",25); student.displayInfo(); }}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!