28. Write a Java program to create a class called Rectangle with private instance variables length and width. Provide public getter and setter methods to access and modify these variables.
class Rectangle{
private double length, breadth;
public void setLength(double l){
length = l;
}
public void setBreadth(double b){
breadth = b;
}
public double getLength(){
return length;
}
public double getBreadth(){
return breadth;
}
}
class Main{
public static void main(String[] args){
Rectangle b1 = new Rectangle();
b1.setLength(10.3);
b1.setBreadth(18.38);
System.out.println("Length : " + b1.getLength());
System.out.println("Breadth : " + b1.getBreadth());
}
}
OUTPUT
Length : 10.3
Breadth : 18.38