Abstract Classes & Interfaces
These notes are from a good explanation taken from Jason Wertz videos on youtube Abstract class A class that represents a generalisation but is ONLY intended to be extended NOT…
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…
Simple “this” keyword example
ThisKeyword.java FunObject.java Outputs: 20 30 50 2 3 50 The THIS keyword allows us to distinguish between the variables of the class, and the variables being passed to the constructor…
Abstract classes an methods
Abstract classes do pretty much what classes do but with a bit of restriction. Example 1 (abstract classes) Take the following code: An abstract class Car.java StartingPoint.java The above code…
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…
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…
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)…
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…
“Is a” vs “Has a” relationship
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…
- 1
- 2
- 3
- 4
- …
- 7
- Go to the next page