Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

thread program

Posted on 2011-04-26
3
Medium Priority
?
315 Views
Last Modified: 2012-05-11
>>What will happen when you attempt to compile and run this code?

public class Runt implements Runnable{
public static void main(String argv[]){
        Runt r = new Runt();
        Thread t = new Thread(r);
        t.start();
        }

        public void start(){
        for(int i=0;i<100;i++)
                System.out.println(i);
        }
}
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


Answer

3) Compile time error: class Runt is an abstract class. It can't be instantiated.

The class implements Runnable but does not define the run method.








I have not understood above question and answer clearly from link
http://www.jchq.net/certkey/0701certkey.htm 

>>class Runt is an abstract class

Runt never mentioned as abstract any where.



Any ideas, resources, links, sample code highly appreciated. thanks in advance.
0
Comment
Question by:gudii9
  • 2
3 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 35471315
Runt declares that it implements Runnable.

If so, it should implement
public void run() method

If it does not  (like in this code) it will immedaitely generate compiler error
0
 
LVL 47

Accepted Solution

by:
for_yan earned 1200 total points
ID: 35471341

About "abstract" it is diagnostic message,
as compiler saw "implements Runnable" it added
method
public void run()
to the list of methods which need to be implemented

This list could also have some methods which could have been
there becuaes the class coul have extended some abstract class
Compiler makes common pool of all methods which need to be implemented
Then it checks those whiich are indeed implemented aginst those which need to
be implemeneted - abnd discovers
that some are not - so it makes conclusion that
this class cannot be instantiated as it has some methods not implemeneted
I think it is just wording of error message taht may be a little bit confusing
but the point is the same
public void run()
is not implemented

0
 
LVL 92

Assisted Solution

by:objects
objects earned 800 total points
ID: 35471532
3) is actually only partly correct in that it won't compile.
"class Runt is an abstract class. It can't be instantiated." - that is not the reason, you would only get that error if Runt was declared abstract (which its not)
The compiler error will be "The type Runt must implement the inherited abstract method Runnable.run()"
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month21 days, 5 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question