Question: Show the output of the following programs. Program 1 public class Test { public static void main( String[] args ){ A a = new A(

Show the output of the following programs.

Program 1

public class Test {

public static void main(String[] args){

A a = new A();

a.p(10);

a.p(10.0);

}

}

class B {

public void p(double i) {

System.out.println(i * 2);

}

}

class A extends B {

// This method overrides the method in B

public void p(double i) {

System.out.println(i);

}

}

Program 2

public class Test {

public static void main(String[] args){

A a = new A();

a.p(10);

a.p(10.0);

}

}

class B {

public void p(double i) {

System.out.println(i * 2);

}

}

class A extends B {

// This method overloads the method in B

public void p(int i) {

System.out.println(i);

}

}

Show the output of the following programs.

public class Faculty extends Employee {

public static void main(String[] args) {

new Employee();

}

public Faculty() {

super();

System.out.println("Faculty's no-arg constructor is invoked");

}

}

class Employee extends Person {

public Employee() {

super("Invoke Persons overloaded constructor");

System.out.println("Employee's no-arg constructor is invoked");

}

}

class Person {

public Person () {

System.out.println("Person's no-arg constructor is invoked");

}

public Person (String s) {

this();

System.out.println(s);

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 Databases Questions!