I am not sure the following two statements are true? q24. (1) Each method in a parent class can be overridden at most once in any one subclass (3) Overriding methods must return exactly the same type as the method they override The answer indicates they are true, but I doubt about them. Please help. jordan
Hi Jordan, They are both true. (1) When you override a method you have to use the same signature ; if you declare two methods with the same signature, in the same class, you get a compile error. (3) One of the rules of overriding is that the overriding method must have the same return type. See JLS �8.4.6.3 Hope that helps. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform [This message has been edited by Jane Griscti (edited June 20, 2001).]
Hi Jordan, A subclass can only override an instance method in the parent by creating one overriding method. Here's an example
1. this is a legal override of <code>method()</code> in <code>SuperA</code>. It has the same signature (method name and parameters) and the same return type. 2. produces a compile error, the previous method has the same signature, you cannot have two methods with the same signature in the same class. 3. produces a compile error, it is not legal for the same reason as (2) and it is not legal as an 'overload' because it does not have different parameters. 4 & 5 both overload the <code>method()</code> in <code>SubA</code>. They have the same name but different parameter lists. An overload method may also have a different return type. Daniel, 'static' methods cannot be overridden as they are not instance methods; overriding only applies to instances. See the Sun Tech Tip on Shadowing. Hope that helps. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform [This message has been edited by Jane Griscti (edited June 23, 2001).]
Post by:autobot
I hired a bunch of ninjas. The fridge is empty, but I can't find them to tell them the mission.
a bit of art, as a gift, the permaculture playing cards