-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolymorphism_intro.java
More file actions
46 lines (35 loc) · 888 Bytes
/
Copy pathPolymorphism_intro.java
File metadata and controls
46 lines (35 loc) · 888 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
43
44
45
46
class Student1
{
//properties
String name;
int age;
//functions
//overloading: compile time: checks for correct implementation
//convention: overloaded func should have diff return type
//overloaded func should have diff type of arguments
//overloaded func should have diff no.of arguments
//compile time polymorphism better than run time polymorphism
public void printinfo(String name)
{
System.out.println(name);
}
public void printinfo(int age)
{
System.out.println(age);
}
public void printinfo(String name,int age)
{
System.out.println(name+" "+age);
}
}
public class Polymorphism_intro {
public static void main(String[] args) {
// TODO Auto-generated method stub
Student1 s1=new Student1();
s1.name="aman";
s1.age=22;
s1.printinfo(s1.name);
s1.printinfo(s1.age);
s1.printinfo(s1.name, s1.age);
}
}