Page 1 of 1

4) - Show the output of following program: 1 public class Test { 2 public static void main(String[] args) { 3 A a = new

Posted: Sun Jul 10, 2022 11:29 am
by answerhappygod
4 Show The Output Of Following Program 1 Public Class Test 2 Public Static Void Main String Args 3 A A New 1
4 Show The Output Of Following Program 1 Public Class Test 2 Public Static Void Main String Args 3 A A New 1 (78.85 KiB) Viewed 42 times
4) - Show the output of following program:1 public class Test {2 public static void main(String[] args) {3 A a = new A(3);4 }5 }67 class A extends B {8 public A(int t) {9 System.out.println("A's constructor is invoked");10 }11}1213 class B {14 public B() {15 System.out.println("B's constructor is invoked");16 }17 }Is the no-arg constructor of Object invoked when new A(3) isinvoked?
5) - Show the output of following program:public class Test {public static void main(String[] args) {new A();new B();}}class A {int i = 7;public A() {setI(20);System.out.println("i from A is " + i);}public void setI(int i) {this.i = 2 * i;}}class B extends A {public B() {System.out.println("i from B is " + i);}public void setI(int i) {this.i = 3 * i;}}
6) - What is wrong in the following code?1 public class Test {2 public static void main(String[] args) {3 Object fruit = new Fruit();4 Object apple = (Apple)fruit;5 }6 }78 class Apple extends Fruit {9 }1011 class Fruit {12 }
2) Show the output of the following code public class Test { public static void main(String[] args) { new Person().printPerson (): new Student ().printPerson(); } } class Student extends Person { @Override public String getInfo() { return "Student": } } class Person { public String getInfo() { return "Person"; } public void printPerson() { System.out.println(getInfo()); } (a) public class Test { public static void main(String[] args) { } class Student extends Person { private String getInfo() { return "Student"; } } } class Person { private String getInfo() { return "Person"; new Person().print Person (): new Student ().printPerson(); } public void print Person () { System.out.println (getInfo(); } (b)
3) What is the output of running the class in (a)? What problem arises in compiling the program in (b)? class A [ public A() { System.out.println( "A's no-arg constructor is invoked"); class B extends A { public class C { public static void main(String[] args) { B b = new B(); (a) class A { public A(int x) { |} class B extends A { public B() { public class C { public static void main(String[] args) { B b = new B(); } (b)