| Author |
is this Ambiguous?
|
pallavi utukuri
Ranch Hand
Joined: Feb 10, 2004
Posts: 182
|
|
this one is from Marcus Green tutorial: 1) Compilation and output of count from 0 to 99 2) Compilation and no output 3) Compile time error: class Runt is an abstract class. It can't be instantiated. 4) Compile time error, method start cannot be called directly Ans: 3 as Runt doesnt implement public void run(){} that does not make Runt as abstract the option should be Runt is not abstract and does not override abstract method run() infact if the code is changed as public abstract class Runt implements Runnable{ then the error would be Compile time error: class Runt is an abstract class. It can't be instantiated. is'nt this Ambiguous? (Code tags added) [ April 19, 2004: Message edited by: Barry Gaunt ]
|
Thanks,<br />Pallavi
|
 |
Yogesh Chhawasaria
Ranch Hand
Joined: Apr 02, 2004
Posts: 53
|
|
I think somewhere your interpretation is wrong. From the JLS An abstract class is a class that is incomplete, or to be considered incomplete. Only abstract classes may have abstract methods , that is, methods that are declared but not yet implemented. If a class that is not abstract contains an abstract method, then a compile-time error occurs. A class C has abstract methods if any of the following is true: � C explicitly contains a declaration of an abstract method (�8.4.3). � Any of C�s superclasses declares an abstract method that has not been implemented (�8.4.6.1) in C or any of its superclasses. � A direct superinterface (�8.1.4) of C declares or inherits a method (which is therefore necessarily abstract) and C neither declares nor inherits a method that implements it. In the given code u have implemented Runnable Interface But not implemented the run() method So you inherit a method from runnable interface but dont implement it so that makes your class abstract. So provide the method body(and then u can instantiate the class ) or declare it abstract()
|
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
|
 |
pallavi utukuri
Ranch Hand
Joined: Feb 10, 2004
Posts: 182
|
|
thanku dat makes sense
|
 |
Vincent Botteman
Greenhorn
Joined: Apr 21, 2004
Posts: 1
|
|
I think the correct answer should be: "Class Runt should be declared abstract" because now the keyword abstract is missing. Answer 3 seems to give you the idea that the class Runt is already abstract. If I compile the code then this is the error I receive: Runt.java:1: Runt is not abstract and does not override abstract method run() in java.lang.Runnable
|
 |
 |
|
|
subject: is this Ambiguous?
|
|
|