-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverridingAndOverloading.java
More file actions
42 lines (38 loc) · 892 Bytes
/
OverridingAndOverloading.java
File metadata and controls
42 lines (38 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* overriding means to override the functionality of an existing method.
* Rule||||||||
* Method name and signature should be identical in super and sub class.
*
*/
public class OverridingAndOverloading
{
public static void main(String[] args)
{
Dog d = new Dog();
d.move();
d.A_Move();
d.A_Move("I am overloaded method!");
}
}
class Animal
{
public void move()
{
System.out.println("Animals can move!!");
}
}
class Dog extends Animal
{
public void move()
{
System.out.println("Dogs can move!!");
}
public void A_Move(){
super.move();
}
//If a class has multiple methods having same name but different in parameters, it is known as Method Overloading.
//Method overloading is not possible by changing the return type of the method only because of ambiguity.
public void A_Move(String s){
System.out.println(s);
}
}