What is the output of the following code? class A { void foo() { System.out.println(“1”); } public A() { System.out.println(“2”); foo(); } } class B extends A { public B() { System.out.println(“3”); } void foo() { System.out.println(“4”); } } public class Client { public static void main(String [] args) { new B(); } }
What is the output of the code below? Explain the observed b…
What is the output of the code below? Explain the observed behavior in detail. String s1 = “hello”; String s2 = “hello”; System.out.println( s1 == s2 ); // output:
Following Type Eraser, how does the code below look like? …
Following Type Eraser, how does the code below look like? Before: class GeometricObject { public double getArea() {return 1.0;} } public static boolean equalArea(E object1, E object2) { return object1.getArea() == object2.getArea(); } After: ?
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 Sub(); }
Does the code below compile? Explain. public class Utils…
Does the code below compile? Explain. public class Utils { public static void main(String[] args ) throws Exception { E e = new E(); } }
Given 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;} }
Given 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); } }
If a car’s gas mileage is modeled by a quadratic function
If a car’s gas mileage is modeled by a quadratic function
A contract contains a provision that states it will be effec…
A contract contains a provision that states it will be effective for a “year.” The plaintiff in a lawsuit claims that a “year” is obviously 12 months. The defendant claims that the contract meant a 10-month school year. Parol evidence:
Barry’s Sport Shop calls Champs Tee Shirt Company to order 2…
Barry’s Sport Shop calls Champs Tee Shirt Company to order 200 designer tee shirts at $2 per shirt. The next day, Barry decides he can easily sell 100 more. Before the order is filled, he calls to change the order to 300 tee shirts. Champs sends 200. Can Barry force Champs to send the additional 100?