✔ JAVA CHAPTERS:-
1. Introduction to Java
2. Features of Java
3. Java Virtual Machine
4. D/F B/W JVM, JRE, JDK
5. Java Data Types
6. Java Programs
7. Setting Java Path
8. OOPs Concepts
9. Object & Class In Java
10. OOPs Continued
11. Encapsulation & Polymorphism
12. Method Overloading
13. Method Overriding
14. Dynamic Method Dispatch
15. Association In Java
16. Inheritance in Java
17. Aggregation in java
18. Command Line Argument
19. Execute Command Line
20. Read Input From Command Line
21. Abstract Class In Java
22. Interface in Java
23. Cutom Marker Interface
24. Constructor In Java
25. Package in Java
26. Acess Modifier In Java
27. Static Import In Java
28. Package Class In Java
29. This Keyword
30. Instance Intializer Block
31. Super Keyword
32. Static Keyword
33. Final Keyword
1. Introduction to Java
2. Features of Java
3. Java Virtual Machine
4. D/F B/W JVM, JRE, JDK
5. Java Data Types
6. Java Programs
7. Setting Java Path
8. OOPs Concepts
9. Object & Class In Java
10. OOPs Continued
11. Encapsulation & Polymorphism
12. Method Overloading
13. Method Overriding
14. Dynamic Method Dispatch
15. Association In Java
16. Inheritance in Java
17. Aggregation in java
18. Command Line Argument
19. Execute Command Line
20. Read Input From Command Line
21. Abstract Class In Java
22. Interface in Java
23. Cutom Marker Interface
24. Constructor In Java
25. Package in Java
26. Acess Modifier In Java
27. Static Import In Java
28. Package Class In Java
29. This Keyword
30. Instance Intializer Block
31. Super Keyword
32. Static Keyword
33. Final Keyword
Encapsulation and Polymorphism In Java: Previous Next: Method Overriding
Method overloading in Java
Method overloading is the way of implementing static/compile time polymorphism in java. Method overloading means more than one methods in a class with same name but different parameters. Parameters can be differing in types, numbers or order. Compiler resolve method call by matching method signature at compile time, that’s why it is known as static or compile time polymorphism. It is also known as static binding.
Ways to implement method overloading in java:
- 1. Parameters differ in types.
- 2. Parameters differ in number.
- 3. Parameters differ in order.
1. Parameters differ in types.
Example:
Below example have two methods which have the same name bur method parameters are differ in their order.
AddExample.java
AddExample.java
Output:
2. Parameters differ in number.
Example:
Below example have two methods which have the same name but method parameters are differ in number.
AddExample.java
AddExample.java
Output:
3. Parameters differ in order.
Example:
Below example have two methods which have the same name bur method parameters are differ in their order.
AddExample.java
AddExample.java
Output:
Why method overloading is not possible by changing return type of the method?
Method overloading is not possible by changing return type of the method. Because, as discussed above compiler resolve method call by matching method signature(method name and parameters). If method signatures are same for two or more methods then how compiler will know which method have to be called.
AmbiguityInOverloading.java
AmbiguityInOverloading.java
Output:
Note: main method can also be overloaded.
MainMethodOverloding.java