Super keyword (calling constructors)
Outputs: Inside A constructor Inside B constructor Inside C constructor Why? When constructor C is called, it actually calls constructor B, which called constructor A. Likewise if we called constructor…
Outputs: Inside A constructor Inside B constructor Inside C constructor Why? When constructor C is called, it actually calls constructor B, which called constructor A. Likewise if we called constructor…
With the Super keyword, you can: Call superclass methods Call superclass constructors Look at the following example: This outputs: Exception in thread "main" java.lang.StackOverflowError at Square.getInformation(Test.java:30) at Square.getInformation(Test.java:30) at Square.getInformation(Test.java:30)…
A subclass method overrides its superclass method if it has the same name a parameter types as its superclass. Output: 4 sides You can notice the subclass and the superclass…
Methods and variables defined in a subclasses are only available inside the subclass and it's subclasses A subclass becomes the superclass for its subclasses Important: A subclass has NO ACCESS…
Output: 4 Star 4 Important: The subclass CANNOT access PRIVATE variables and methods of the superclass
Food is the superclass and Cat and Dog are the subclasses, as they inherit all the methods and variables of the food superclass. Example 1) Outputs: I am the eat…