Show the output of the following programs. 1) abstract class Furniture { abstrac
ID: 3564780 • Letter: S
Question
Show the output of the following programs.
1)
abstract class Furniture { abstract void prnt();}
class Recliner extends Furniture {
void prnt() { System.out.println("I'm a recliner");}
}
class LaZBoy extends Recliner {
void prnt() { System.out.println("I'm a lazboy");}
}
public class furnitureTest2 {
public static void main(String[] args) {
Furniture [] A = { new Recliner(), new Recliner(), new LaZBoy()};
for (int i=0; i<3; ++i)
A[i].prnt();
}
}
2)
class A { int x = 1; }
class B extends A { }
class C extends B { int x = 2;}
public class classTest {
public static void main(String[] args) {
A w = new A(); System.out.println(w.x);
B u = new B(); System.out.println(u.x);
C v = new C(); System.out.println(v.x);
A [] a = { new A(), new B(), new C()};
for (int i=0; i<3; ++i)
System.out.println(a[i].x);
}
}
Explanation / Answer
A. Because the super is abstract, the children even though in an array use their own definition of the function
I'm a recliner
I'm a recliner
I'm a LazBoy
B.
1
1
2
But the loop produces because they inherit from the super class only inside the array.
1
1
1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.