Abstract Class

Abstract class is the class which can hold fully implemented methods and unimplemented methods. That’s the major difference between Interface vs Abstract class.
Have a look on below section 1.0, which demonstrate template for Abstract class.

Some key points about above demo: 
  1. abstract keyword is used.
  2. Object can’t be created for abstract class.
  3. If any method is ‘abstract’ then it’s must to add keyword ‘abstract’ for the class.
  4. If any class is abstract then it’s doesn’t mandatory that any/all method will be abstract.
  5. Private method  someComplexCalculation() is implemented method.
  6.  setValue() is abstract method.
    public abstract int setValue();
    That’s the reason the class ‘TechnicalJungleAbstract’ became ‘abstract’.
    This method is getting overridden by the class who is inheriting abstract class.
    Section 1.1 is inhering abstract class. So this class is only overriding setValue() class.
  7. Section 1.1 is overriding setValue() method and its public. Its must be public only.

 

Some key points about above demo: 

 

If developer doesn’t want to implement/override ‘abstract’ methods ( of abstract class) then add ‘abstract’ before method and class both.

  1. JungleFirst class is further extending ‘abstract’ class only. So method and class both are abstract.
  2. Finally JungleSecond class is implementing all available abstract methods.
  3. Class JungleSecond has main method and object is creating created for JungleSecond class only.
  4. Mind it, no where, abstract class has been instantiated.
If you like the post then please socialize it. Happy Sharing. Loudly Subscribing.

2 Comments

  1. Pingback: Java Made Easy - Technical Jungle

  2. Pingback: ContentObserver and ContentObservable | Android | Details - Technical Jungle

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.