Inner class

I took these examples from Vinod Pillai lecture on youtube but I think there may be mistakes in his explanations Inner classes Outputs: Inner class display Outer class display Outer…

Continue Reading Inner class

Implementing interfaces

An interface is a way of organising code, take the following example that may apply to a game scenario: CharacterInterface.java Then in the game we have characters; James.java and Emma.java…

Continue Reading Implementing interfaces

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…

Continue Reading Super keyword (calling constructors)

Super keyword (calling superclass methods)

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)…

Continue Reading Super keyword (calling superclass methods)

Method Overriding

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…

Continue Reading Method Overriding