What is the output of the code below? Explain. (Note: there…
What is the output of the code below? Explain. (Note: there are no compilation errors) class A { public int x; public A(int x) { this.x = x; } public String toString() { return “x = ” + x; } } class Super { public A a; public Super() { System.out.println(“Super()”); foo(); } public Super (A a) { System.out.println(“Super(A a)”); this.a = a; foo(); } public void foo() { System.out.println(“Super.foo()”); System.out.println(a); } } public class Sub extends Super { public A a; public Sub() { System.out.println(“Sub()”); foo(); } public Sub (A a) { System.out.println(“Sub(A a)”); this.a = a; foo(); } @Override public void foo() { System.out.println(“Sub.foo()”); System.out.println(a); } } public static void main(String[] args) { new Super(); }
Read DetailsGiven the class hierarchy below. Could the symmetry of equal…
Given the class hierarchy below. Could the symmetry of equals() be violated? If yes, provide client code that demonstrates that. class A { int x; public A(int x) {this.x = x;} public boolean equals(Object o) { if (!(o instanceof A)) return false; A a = (A)o; return this.x == a.x; } } class B extends A { public B(int x) {super(x); } public boolean equals(Object o) { if (!(o instanceof B)) return false; B b = (B)o; return super.equals(o); } }
Read DetailsGiven the class hierarchy below. Could the symmetry of equal…
Given the class hierarchy below. Could the symmetry of equals() be violated? If yes, provide client code that demonstrates that. class A { int x; public A(int x) {this.x = x;} public boolean equals(Object o) { if (!(o instanceof A)) return false; A a = (A)o; return this.x == a.x; } } class B extends A { int y; public B(int x, int y) {super(x); this.y = y;} public boolean equals(Object o) { if (!(o instanceof B)) return false; B b = (B)o; return super.equals(o); } }
Read DetailsMallory orally agrees to buy 500 electronic cash registers f…
Mallory orally agrees to buy 500 electronic cash registers from Thomas for $25,000. Thomas delivers 300 cash registers to Mallory, who receives and accepts them. Which of the following is correct with regard to this transaction?
Read Details