-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.java
More file actions
39 lines (29 loc) · 898 Bytes
/
Copy pathRectangle.java
File metadata and controls
39 lines (29 loc) · 898 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
//Problem Statement:
//Objective: Develop a basic Java program to understand class and initialize the instance variable of a class.
//
//Problem Description: Develop a class "Rectangle". The class should have two instance variables with private access modifier.
//
//length: int (length is the variable and int is the data type)
//breadth: int
//Use setter methods to initialize the instance variables.
public class Rectangle{
private int length;
private int breadth;
public void setLength(int len) {
this.length = len;
}
public void setWidth(int wid) {
this.breadth = wid;
}
public void display() {
System.out.println(length);
System.out.println(breadth);
}
// main method
public static void main (String [] args ) {
Rectangle rect = new Rectangle();
rect.setLength(10);
rect.setWidth(30);
rect.display();
}
}