Q1 Inhertiance21 PointsGrading comment: For each of the following, tell if the code will compile. If so,
Fantastic news! We've Found the answer you've been seeking!
Question:
Q1 Inhertiance21 PointsGrading comment:
For each of the following, tell if the code will compile. If so, what will be be printed? If not, why will it not compile?
Give a one sentence reasoning for EITHER outcome. (No reasoning gets max 1 point.) Note: Syntax errors, if any, are inadvertent and should be ignored. Also, code outside of an explicit class is considered to be in the main method of some arbitrary class in the same package. (Fields that are not private are accessible to all classes in same package.)
Q1.44 PointsGrading comment:
public class X { public int x=2; public int getX() { return x; } public String toString() { return x + ""; } } public class Y extends X { public int y=3; public String toString() { return (getX() + y) + ""; } } X x = new Y(); System.out.println(x);
Q1.54 PointsGrading comment:
public class A { public int x; public A(int x) { this.x = x; } } public class B extends A { public static void main(String[] args) { System.out.println("B"); } }
Q1.63 PointsGrading comment:
public class M { public static int mn=2; } public class N extends M { public int mn; } M m = new N(); System.out.println(m.mn);
Related Book For
Posted Date: