Question: What is the output of the following code? IN JAVA public class hw1{ public static void main(String[] args) { System.out.println(new A()); System.out.println(new B()); } }
What is the output of the following code?
IN JAVA
public class hw1{ public static void main(String[] args) { System.out.println(new A()); System.out.println(new B()); } } public class A { public int i; public A() { i = 1; } public String toString() { return String.format("2 %d", i); } } public class B extends A { public B() { i = 3; } public String toString() { return String.format("4 %d", i); } } 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
