Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package rectangle;
- public class Rectangle {
- int length, width;
- }
- class RectArea {
- public static void main(String[] args) {
- int area;
- Rectangle rect = new Rectangle();
- rect.length = 14;
- rect.width = 13;
- area = rect.length * rect.width;
- }
- }
- area = rect.area;
- public class Rectangle {
- int length, width, area;
- void getData(int x, int y) {
- length = x;
- width = y;
- area = length * width;
- }
- }
- int length, width, area;
- void getData(int x, int y)
- {
- length=x;
- width=y;
- }
- int rectArea()
- {
- area=length*width;
- return area;
- }
- }
- class RectArea{
- public static void main(String[] args) {
- int area1, area2;
- Rectangle rect1 =new Rectangle();
- Rectangle rect2 =new Rectangle();
- rect1.length=14;
- rect1.width=13;
- area1=rect1.length*rect1.width;
- rect2.getData(13,14);
- area2=rect2.rectArea();
- System.out.println("Area1="+ area1);
- System.out.println("Area1="+ area2);
- System.out.println("Area1="+ rect2.area);
- }
- }
Add Comment
Please, Sign In to add comment