Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Astract Class  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the practical significance of abstract class?
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

ashish sood wrote:What is the practical significance of abstract class?



What do you think it is? What did google tell you? What happened when you created one? Can you find any examples of abstract classes in the API?
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

ashish sood wrote:What is the practical significance of abstract class?


So that other developers have to do some coding to fill in the implementation of all abstract methods which you were unable to program at present

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think of an abstract class as an interface that allows you to provide some implementation but leave other things for a subclass to implement.
Like an interface, you cannot directly instantiate an abstract class. Unlike an interface, not every abstract method need be public. An abstract class is like saying "Here, I'll provide you with the implementations of things that are probably commonly reusable to all subtypes, I'll even define the method names for other stuff all subtypes must do but you have to fill in their implementation." Just as an interface must be implemented to be used, an abstract class generally must be extended to be useful. From the compilers point of view actually, interfaces actually are abstract classes with all public abstract methods.
 
Kevin Workman
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Alex Hurtt wrote:From the compilers point of view actually, interfaces actually are abstract classes with all public abstract methods.



Is that really true? You can't implement an abstract class. You can't extend an interface. There are important differences, especially to somebody first trying to understand interfaces and abstract classes.
 
Marshal
Posts: 58395
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and you can add implemented methods to abstract classes. If you try adding methods to an interface, you will "break" all its implementing classes. But if you add implemented methods to an abstract class, they are immediately available in all its subclasses.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!