a The T class contains two lines which will not compile Cross out the two lines

A the t class contains two lines which will not

This preview shows page 10 - 13 out of 13 pages.

a)The T class contains two lines which will not compile. Cross out the two lines. (Note: Classes A and B contain no errors.) b)The main method in T contains casts which are legal (no compilation error) but unnecessary. Circle these lines. c)The main method in T contains one or more lines which will cause a runtime error. Underline these lines. d)If the lines containing compilation errors or runtime errors are eliminated, what is the output when main is run?
Image of page 10
11 Q10. Consider the following classes and interface: (20 marks) public interface J { String a(int i); } public abstract class K implements J { protected String s = "x"; @Override public String a(int i) { return s + (i+5); } } public class P extends K { } public class Q extends P { @Override public String a(int i) { return new String(s + (i + 3)); } } public class R extends Q { public R() { s = "y"; } @Override public String a(int j) { return "" + super.a(j) + j; } }
Image of page 11
12 What is the output when the main method in Main is run? Q11. What is the output when the main method from the following code is run? (20 marks) public class C implements Comparable<C> { private double d; public C(double dd) { d = dd; } @Override public int compareTo(C other) { return (int) (d - other.d); }
Image of page 12
13
Image of page 13

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture