• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can abstract class works as independent?

 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think, as long as you don't create an instance of an abstract class - you 're fine.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic