Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can abstract class works as independent?

 
yamini nadella
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think, as long as you don't create an instance of an abstract class - you 're fine.
 
C. Magmanum
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...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
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic