• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

is this Ambiguous?

 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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()
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanku dat makes sense
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic