-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPractice11.java
44 lines (37 loc) · 992 Bytes
/
Practice11.java
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
43
44
/*
Polymorphism: One thing present in many forms.
Compiler has to decide which process is to be executed during compile time.
Method overloading: Many methods present with a same name but different arguments.
Method Overriding: Method with the same name and argument but present in the different classes(parent and child class).
*/
class Parent
{
void f1()
{
System.out.println("I'm Parent function 1");
}
void f1(int num)
{
System.out.println("I'm Parent function " + num);
}
}
class Child extends Parent
{
void f1()
{
System.out.println("I'm Child function 1");
}
}
class Practice11
{
public static void main(String[] args)
{
System.out.println("Here overriding exectes");
Child ch = new Child();
ch.f1(); // Overriding
System.out.println("\nHere overloading exectes");
Parent pa = new Parent();
pa.f1(); // Overloading
pa.f1(2); // Overloading
}
}