-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShapeNew.java
More file actions
39 lines (34 loc) · 1.06 KB
/
Copy pathShapeNew.java
File metadata and controls
39 lines (34 loc) · 1.06 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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
/**
*
* @author DELL
*/
// this is the initilization of object using reference variable
class Rectangle{
double length, breadth; // this is instance variable
/*void area(){ // without calling function no return type
System.out.println("The area is "+ length * breadth);
}*/
double area(){
return length * breadth;
}
}
public class ShapeNew {
public static void main(String[] args) {
Rectangle r1 = new Rectangle(); // initilize object using reference variable
Rectangle r2 = new Rectangle();
r1.length = 3.778;
r1. breadth = 5;
r2.length = 5;
r2.breadth= 8;
/*
r1.area();
r2.area();
*/
System.out.println("The area is "+r1.area());
System.out.println("The area is "+r2.area());
}
}