Rules for overriding a method
Same signature
At least as accessible
No new or broader exceptions
covariant returns (Covariant return type works only for non-primitive return types)
Rules for hiding a method
Same signature At least as accessible No new or broader exceptions covariant returns (Covariant return type works only for non-primitive return types) marked static
Abstract Class Definition Rules
No direct instantiation
Zero or more methods
No private, protected, or final
A child abstract class inherits all parent abstract methods
First concrete class implements all abstract methods
Abstract Method Definition Rules
Only in abstract classes
No private or final
No body
Same rules for overriding a method
Rules for defining an interface
No direct instantiation Zero or more methods No final Assumed public or default. Assumed abstract. Non default methods assumed abstract and public
Default interface method rules
Only declared in an interface.
Must be marked default and have a method body.
Not assumed static, final, or abstract.
May be overridden.
Assumed to be public. Will not compile if marked private or protected.
A default method is a method defined within an interface with …
the default keyword in which a method body is provided.
Classes have the option to override the default method if they need to, but…
they are not required to do so.
If the class doesn’t override the method…
the default implementation will be used.
Interface variables are assumed to be…
public, static, and final.
Marking any interface variable private or protected will …
trigger a compiler error as will marking any variable abstract.
The value of an interface variable must be set…
when it is declared since it is marked as final.
If two different interfaces have the same method (including signature and return type), you can define a class…
that fulfills both interfaces simultaneously.
If two abstract interface methods have the same method name but different input parameters, …
there is no conflict because this is considered a method overload.
If two different interfaces have the same methods with the same signatures but different return types, …
the class attempting to inherit both interfaces will not compile.
Rules for extending an interface
interfaces inherit all abstract methods from parent concrete class must implement all of an interface's abstract methods
The keywords abstract and public…
are assumed for interfaces.
A class may implement multiple interfaces, …
each separated by a comma.
A concrete class is the first nonabstract subclass that extends an abstract class and …
is required to implement all inherited abstract methods.
A concrete subclass is not required to provide an implementation for an abstract method if…
an intermediate abstract class provides the implementation.
If a method in a child class has the same signature as a method in the parent class, but one of them is static and the other isn’t, …
the child method will not compile.
You can override a private method in a parent class with a method in the child class,…
so long as it is private too.