Guest User

Untitled

a guest
Jul 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. /*
  2. * An abstract class should have atleast one abstract method
  3. * It can have non abstract methods also unlike interfaces
  4. * Abstract methods cannot be instantiated
  5. * Child classes of an abstract class can of-course be instantiated, and if the abstract class has a constructor, then child class on instansiation
  6. * will call the abstract class instance first and then will call the child class constructor
  7. * An abstract class non abstract methods are always static, as the abstract class cannot be instantiated, and therefore if these methods are not static,
  8. * they wont be able to be directly called from abstract class name
  9. * Abstract class abstract methods should not be static, as they have to be implemented by child class who calls these methods through object
  10. * instance of child class of type parent (Abstract class)
  11. * Non abstract methods of an abstract class can be overridden by child classes and that method overridden can be called by child class objects
  12. * Interesting one (for me to check more as well) - Child class object can call static methods with bodies implemented in abstract classes directly by
  13. * instance of child class (need to see this, as child class should ideally not be able to call static methods with an instance)
  14. */
  15. public abstract class AbstractClass {
  16.  
  17. public AbstractClass() {
  18. System.out.println("Abstract Class Constructor");
  19. }
  20.  
  21. //Declare abstract methods of the abstract class
  22. public abstract void add(Integer a, Integer b);
  23. public abstract void subtract(Integer a, Integer b);
  24.  
  25.  
  26. public void introduce() {
  27. System.out.println("This class is an abstract class");
  28. System.out.println("My name is Rajat, we are beginning to learn JAVA's abstract classes");
  29. }
  30.  
  31. }
Add Comment
Please, Sign In to add comment