aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes can abstract class works as independent? 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 "can abstract class works as independent?" Watch "can abstract class works as independent?" New topic
Author

can abstract class works as independent?

yamini nadella
Ranch Hand

Joined: Apr 13, 2004
Posts: 257
import java.io.*;
public abstract class test1
{
public static void main(String args[])
{
char c = 'a';
System.out.println("hello "+c);
}
public abstract void hello();
}
-----------
I am able to compile and execute above class as > java test1
is there any meaning?
Svitlana Dukhovna
Ranch Hand

Joined: Jan 13, 2004
Posts: 37
I think, as long as you don't create an instance of an abstract class - you 're fine.
C. Magmanum
Ranch Hand

Joined: Apr 03, 2004
Posts: 35
...as Dukhovna stated abstract classes can't be instantiated.
and u can virtually declare any class as abstract even if it doesnt contain any abstract method. It is a must that u declare it abstract if it actually does contain an abstract method.
Ramnath krishnamurthi
Ranch Hand

Joined: Jan 22, 2003
Posts: 56
Hi,
First of all if you look at the main method,no instance of abstract class is created
The next point is that the main method is a static one and there fore when you run the above code,it gets executed.
Change your code as per the following and you will get a compile time error
import java.io.*;
public abstract class test1
{
public static void main(String args[])
{
char c = 'a';
System.out.println("hello "+c);
test1 test = new test1();
}
public abstract void hello();
}

HTH,
Ramnath
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can abstract class works as independent?