• 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

Abstract Classes

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any Class containes an abstract method must be declare abstract.
But why it is not vice versa???
For ex. If class declare as abstract and method is not abstract it works fine.
abstract class Test1 {
public static void main(String args[]) {
int i = 0;
System.out.println(i);
}
Output : 0
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
abstarct class with no method declared as abstarct, can be useful when you do not want any other class to instantiate it, but just extend it.
i.e
class B {
public static void main(String args[]) { T t = new T();
}
}
is not possible/ desired.
but, class B extends T, is desired.
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mark a class abstract if it doesn't have any abstract methods, if you know that the class is not complete yet and may want to add more later. You should be allowed (and are) to do that. I don't know how common it is, but it's possible.
 
reply
    Bookmark Topic Watch Topic
  • New Topic