Skip to content

Commit adb2d10

Browse files
authored
Create overloading vs overriding
1 parent 23e08c3 commit adb2d10

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

OOPs/overloading vs overriding

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
OverLoading rules
2+
3+
1. Name of method should be same in each of the classes.
4+
2. Return type and method argument can vary in each classes.
5+
3. Inheritance is not necessary.
6+
7+
8+
OverRiding rules
9+
1. Inheritance is required b/w parent and child classes.
10+
2. Method argument and return type must be same in both the class's method
11+
3. @Override annotation check if method is not overridden/implemented from it's superclass during complilation
12+
4. The access modifier of subclass method should be same or wider than superclass's access modifier
13+
5. If superclass throws error then subclass can either throw same,subclass of that error or no error
14+
6. If superclass throws no error then subclass can only declare unchecked exceptions
15+
16+
private vs final (OverRiding)-
17+
1. final method of superclass gives 'method final' error in compile time
18+
2. private method of superclass gives no error rather it runs the local method
19+
using annotation in such cases gives no overriding done error
20+
When we create object/call of private then we get error

0 commit comments

Comments
 (0)