Super classes, Object, and Class Hierarchy
- Every class have a superclass
- If we don’t define the superclass, by default, it will be the class Object
Object class
- It is the only class that does not have a superclass
Often we need to override the following methods
- toString()
- equals()
- hasCode()
Abstract classes
Using Abstract classes, we can declare classes that define ONLY part of implementation, leaving extended classes to provide specific implementation of some or all the methods
One good example will be
1 | public abstract class Shape { |
We can also invokeshapes[].area()
. Java will automatically use the implementation.
Interfaces in JAVA
All the methods defined within an interface are implicitly abstract, which means that the class/abstract class MUST have implementation for all of its method.