Overloaded methods:

- Overloaded methods MUST change the argument list
- Overloaded methods CAN change the return type
- Overloaded methods CAN change the access modifier
- Overloaded methods CAN declare new or broader checked exceptions
- A method can be overloaded in the same class or in a subclass

Overriding Methods:

- The overriding method cannot have a more restrictive access modifier than the method being overridden (Ex: You can’t override a method marked public and make it protected).
- You cannot override a method marked final.
- You cannot override a method marked static.

 
 

Overriding

Overriding methods:
It allows a subclass to re-define a method it inherits from it's superclass
Overriding methods:
1. It appears in subclasses
2. They have the same name as a superclass method. 
3. They have the same parameter list as a superclass method. 
4. They have the same return type as as a superclass method. 
5. They have the access modifier for the overriding method may not be more restrictive than the access modifier of the superclass method.
  • If the superclass method is public, the overriding method must be public. 
  • If the superclass method is protected, the overriding method may be protected or public.
  • If the superclass method is default, the overriding method may be default, protected, or public.
  • If the superclass methods is private, it is not inherited and overriding is not an issue.

 
 

Overloading

Overloading methods
1.They appear in the same class or a subclass.
2.They have the same method name but, have different argument lists(Compulsory).
3. Can have different return type(Not compulsory).
4. It has nothing to do with inheritance and polymorphism.

 
 
Interfaces cannot be instantiated— they can only be implemented by classes or extended by other interfaces.

 
 

Interface in Java

Interfaces cannot be instantiated, but rather are implemented. A class that implements an interface must implement all of the methods described in the interface, or be an abstract class.

 
 

Interface


 
 

Abstraction in Java

"If a class is abstract and cannot be instantiated, the class does not have much use unless it is subclassed."
A parent class contains the common functionality of a collection of child classes, but the parent class itself is too abstract to be used on its own.

 
 

DDD (Deadly Diamond of Death)

Java doesn't support multiple inheritance because of Deadly Diamond of Death(DDD). What it is ?? Here is an example--

 
 

Multilevel Inheritance in Java

"Cow Class" calling methods that are available inside classes "Herbivore & Animal".  Though "Cow" extends only class "Herbivore", it would in turn inherit the properties of "Animal" extended by "Herbivore" . 

 
 

Inheritance

Base classes(child class) can inherit attributes and behavior from pre-existing classes (superclasses, parent classes)

Single level inheritance