-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem12.java
More file actions
121 lines (83 loc) · 2.49 KB
/
problem12.java
File metadata and controls
121 lines (83 loc) · 2.49 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*Write a java program to implement method overloading concept.
class Student {
String name;
int rollno;
String address;
}
public class problem12 {
// Overloaded methods (same method name, different parameters)
public static void display(String name) {
System.out.println("Name is: " + name);
}
public static void display(int rollno) {
System.out.println("Rollno is: " + rollno);
}
public static void display(String address, boolean check) {
System.out.println("Address is: " + address);
}
public static void main(String args[]) {
Student s = new Student();
s.name = "Rajan";
s.rollno = 17;
s.address = "Padmpur";
// Calling overloaded methods
display(s.name); // Calls display(String)
display(s.rollno); // Calls display(int)
display(s.address, true); // Calls display(String, boolean)
}
}
*/
/*
overriding method area of rectangle and circle:
import java.util.Scanner;
class Area{
int length;
int bredth;
int radius;
void Area(int length, int bredth){
System.out.println("Area of rectangle : "+(length*bredth));
}
void Area(int radius){
System.out.println("Area of circle :"+(3.14*radius*radius));
}
}
public class problem12{
public static void main(String args[]){
Scanner obj=new Scanner(System.in);
Area s=new Area();
System.out.println("Enter the length bredth of rectangle: ");
s.length=obj.nextInt();
s.bredth=obj.nextInt();
System.out.println("Enter the radius of circle: ");
s.radius=obj.nextInt();
s.Area(s.length,s.bredth);
s.Area(s.radius);
}
}
*/
//
//Write a java program to implement method overloading concept:
import java.util.Scanner;
class area{
int l,b,r;
void area(int l,int b){
System.out.println("Area of rectangle is "+(l*b));
}
void area(int r){
System.out.println("Area of circle is "+(3.14*r*r));
}
}
public class problem12{
public static void main(String args[]){
int length,bredth,radius;
Scanner obj=new Scanner(System.in);
System.out.print("Enter the length and bredth of rectangle: ");
length=obj.nextInt();
bredth=obj.nextInt();
System.out.print("Enter the radius of circle: ");
radius=obj.nextInt();
area a=new area();
a.area(length,bredth);
a.area(radius);
}
}