Question: In what follows, you have a code with two errors. Find the errors, specify the type of the error (syntax or compile time error) and
In what follows, you have a code with two errors. Find the errors, specify the type of the error (syntax or compile time error) and explain them. Put your answer in the provided box.
| public class DynamicBindingDemo{ public static void main(String[] args){ m(new MetroTicket()); m(new Ticket()); m(new TrainTicket()); }
public static void m(TrainTicket x){ System.out.println(x.toString()); } }
public class MetroTicket extends TrainTicket{ }
public class TrainTicket extends Ticket{ public String toString(){ return "A Train Ticket"; } }
public class Ticket implements Comparable{ public String toString(){ return "A Ticket"; } }
public interface Comparable{ public abstract int compareTo(Object o); } |
| // Explain error 1 here
|
| // Explain error 2 here
|
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
