File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes abstract class problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "abstract class problem" Watch "abstract class problem" New topic
Author

abstract class problem

Pankaja Shinde
Ranch Hand

Joined: Sep 15, 2006
Posts: 87
abstract class Transaction implements Runnable { }

class Deposit extends Transaction
{
protected void process()
{
addAmount();
}
void undo(int i)
{
System.out.println("Undo");
}
}


What will happen if we attempted to compile the code?

Select the one right answer.

1. This code will not compile because parameter i is not used in undo().
2. This code will not compile because there is no main() method.
3. This code will not compile because Deposit must be an abstract class.
4. This code will not compile because Deposit is not declared public.
5. Everything will compile fine.

Correct answer : 3

Why ?

pankaj
Srinivas Kumar
Ranch Hand

Joined: Jul 14, 2005
Posts: 52
Yes. The answer is correct because the class Deposit does not implement public void run() method which is declared in Runnable interface.
Any nonabstract class implementing directly/indirectly the Runnable interface should implement the run() method.
Antonio Trapero
Greenhorn

Joined: Mar 24, 2007
Posts: 11
2 reasons:

-->First, it has to be abstract. Not implements public void run().
-->Second, look at call to addAmount(); the method is not define. Even class
was abstract , you will still have compilation error.

Oh, dude for me, in third person of conditional, is "class was", or "class were" sorry for my english
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Hi Pankaj,

First you have not given definition to the addAmount() method so it yields to compilation error and if you missed it anyway the answer is obviously 3,
the class also must be abstract to compile successfully because it does not implement the run() method. To compile it successfully either implement the run() method properply (public void run(){}) or make your class abstract to leave the burden of implemetation of interface and abstract class's abstract methods on the first concrete class.

Thanks and regards,
cmbhatt


cmbhatt
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: abstract class problem
 
Similar Threads
static methods in abstract classes
Nested Classes Test
Nested classes & Interface
Help!!!
is this Ambiguous?