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 Executing abstract classes 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 "Executing abstract classes" Watch "Executing abstract classes" New topic
Author

Executing abstract classes

kavi ram
Greenhorn

Joined: Jun 12, 2006
Posts: 13
hi all,
when i execute this code, it display java.lang.NoSuchMethodError:main error. if anybody know please help me.


Thanks in Advance.
abstract class Abs
{
private int i;
public abstract void first();
{
System.out.println("in first");

}

}
Mani Venkata Kanth
Ranch Hand

Joined: Aug 21, 2006
Posts: 39
hi
what's wrong with that output..
there is no main method in your code.when executing it is searching for main method which is the gate way for java console programs. so it is giving runtime exception indicating that there is no main method.
i think your doubt cleared...
if not post your exact doubt..
Praveen Babu
Ranch Hand

Joined: Jul 30, 2006
Posts: 138
Originally posted by kavi ram:
hi all,
when i execute this code, it display java.lang.NoSuchMethodError:main error. if anybody know please help me.


Thanks in Advance.
abstract class Abs
{
private int i;
public abstract void first();
{
System.out.println("in first");

}

}



Do you really want to execute this code with out the main method or can you execute this without main method ? Think about this. You will get the answer yourself.

One more thing,



what is this ?

choices:
1.An instance initializer.
2.Body of abstract method.

Answer: Astract methods cannot have a body.
kavi ram
Greenhorn

Joined: Jun 12, 2006
Posts: 13
hi,
thank to your reply.
But i want to execute this without main method.

help me.
Mani Venkata Kanth
Ranch Hand

Joined: Aug 21, 2006
Posts: 39
well,what is the output your expecting?
Shyam kumar
Ranch Hand

Joined: May 21, 2006
Posts: 146
You cannnot call the class directly without executeing the main method. The JVM looks for the main method of the class to execute it. If you dont want to use main then you need to provide concrete implementation of the class. Use the code below:
abstract class Abs{
private int i;
public abstract void first();
{
System.out.println("in first");

}

}
class Test extends Abs{


public void first(){


}
public static void main(String[] args) {
new Test();
}
}

It will execute the instance initializer block in you abstract class also.

Hope this helps...
kavi ram
Greenhorn

Joined: Jun 12, 2006
Posts: 13
Thanks Sharma.
Jay Suttiruttana
Ranch Hand

Joined: Aug 17, 2006
Posts: 36
On a side note. The abstract class also needs to be extend and have its abstract method define before you can call on that class.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Executing abstract classes
 
Similar Threads
Regarding abstract class
Query in Abstract class
Instance Initializer means what
Abstract classes and Interfaces
java.lang.InstantiationException - When try to call a web service