面向对象(上)类封装举例

import java.util.Scanner;

//—————小汽车类

class Engine{}

class Door{}

class Windows{}

class car{

String pinpai;

float price;

Engine eg1;

Door d[];

Windows w[];

void stop(){}

void start(){}

}

//——————长方形类

class Rectangle {

float len;

float width;

public float area(float len,float width){

return len*width;

}

public float circle(float len,float w){

return 2*(len+width);

}

}

public class Test{ // 主类,引用并测试与矩形之间的关系

Rectangle r1=new Rectangle();

public static void main(String args[]){

Test t1=new Test();

Scanner sc=new Scanner(System.in);

float len=0;

float width=0;

float s=0;

System.out.println("输入R1矩形的长是:");

len=sc.nextInt();

System.out.println("输入R1矩形的宽是:");

width=sc.nextInt();

s=t1.r1.area(len, width);

System.out.println("R1矩形的面积是:"+s);

}

}

展开阅读全文

页面更新:2024-04-06

标签:小汽车   矩形   长方形   面积   关系   测试   科技

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top