-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethod_overloading.java
More file actions
67 lines (53 loc) · 2.09 KB
/
method_overloading.java
File metadata and controls
67 lines (53 loc) · 2.09 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// function overloading we will always do in same class // we cannot do function overloading in different classes
// function overloading is we are writing same function name but passing different no of argument and assigning different task to each
// it is compile time polymorphism because an compile time compiler will decide that at which time which function will work or executed
class Base{
public int data;
private String name;
Base(int x,String str){
data=x;
name=str;
}
public void BaseDetails(){
System.out.println("DATA: "+data); // // Making it in one child class show that we can access it in one call from main function
System.out.println("name: "+name);
}
public void BaseDetails(String abc){
System.out.println("DATA: "+data); // // Making it in one child class show that we can access it in one call from main function
System.out.println("name: "+name);
}
public void BaseDetails(int x){
for (int i = 0; i < x; i++) {
System.out.println("DATA: "+data); // // Making it in one child class show that we can access it in one call from main function
System.out.println("name: "+name);
}
}
public void getName(){
System.out.println("name: "+name);
}
}
class Child extends Base{
public int age;
private String school;
Child(int y,String str2,int x,String str){
super(x,str);
age=y;
school=str2;
}
public void ChildDetails(){
System.out.println("age : "+age);
System.out.println("school: "+school);
System.out.println("DATA: "+data);
super.getName();
}
}
public class method_overloading {
public static void main(String[] args) {
Base b1=new Base(100,"rahul");
// Child c1=new Child(100,"Utkarsh",50,"GD Goenka");
// c1.ChildDetails();
b1.BaseDetails(); //same name but different
b1.BaseDetails("Utkarsh"); //same name but different
b1.BaseDetails(2); //same name but have argument difference
}
}