Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * An abstract class should have atleast one abstract method
- * It can have non abstract methods also unlike interfaces
- * Abstract methods cannot be instantiated
- * Child classes of an abstract class can of-course be instantiated, and if the abstract class has a constructor, then child class on instansiation
- * will call the abstract class instance first and then will call the child class constructor
- * An abstract class non abstract methods are always static, as the abstract class cannot be instantiated, and therefore if these methods are not static,
- * they wont be able to be directly called from abstract class name
- * Abstract class abstract methods should not be static, as they have to be implemented by child class who calls these methods through object
- * instance of child class of type parent (Abstract class)
- * Non abstract methods of an abstract class can be overridden by child classes and that method overridden can be called by child class objects
- * Interesting one (for me to check more as well) - Child class object can call static methods with bodies implemented in abstract classes directly by
- * instance of child class (need to see this, as child class should ideally not be able to call static methods with an instance)
- */
- public abstract class AbstractClass {
- public AbstractClass() {
- System.out.println("Abstract Class Constructor");
- }
- //Declare abstract methods of the abstract class
- public abstract void add(Integer a, Integer b);
- public abstract void subtract(Integer a, Integer b);
- public void introduce() {
- System.out.println("This class is an abstract class");
- System.out.println("My name is Rajat, we are beginning to learn JAVA's abstract classes");
- }
- }
Add Comment
Please, Sign In to add comment