zoukankan      html  css  js  c++  java
  • 构造方法,类创建对象的调用,创建对象,为对象分配成员变量。。(Example4_2)

    class Lader{
     double above,bottom,height;
     Lader(){}
     Lader(double a,double b,double h){
      above=a;
      bottom=b;
      height=h;
     }
     public void setAbove(double a){
      above=a;
     }
     public void setBottom(double b){
      bottom=b;
     }
     public void setHeight(double h){
      height=h;
     }
     double computeArea(){
      return (above+bottom)*height/2.0;
     }
     }
     public class Example4_3{
     public static void main(String args[]){
      double area1=0,area2=0;
      Lader laderOne,laderTwo;
      laderOne=new Lader();
      laderTwo=new Lader(10,88,20);
      laderOne.setAbove(16);
      laderOne.setBottom(26);
      laderOne.setHeight(100);
      laderTwo.setAbove(300);
      laderTwo.setBottom(500);
      area1=laderOne.computeArea();
      area2=laderTwo.computeArea();
      System.out.println("laderOne的above,bottom和heigh:"+laderOne.above+","+laderOne.bottom+","+laderOne.height);
      System.out.println("laderOne的面积:"+area1);
      System.out.println("laderTwo的above,bottom和height:"+laderTwo.above+","+laderTwo.bottom+","+laderTwo.height);
      System.out.println("laderTwo的面积:"+area2);
      
     }
    }

  • 相关阅读:
    Linux入门
    服务器核心知识
    跨域
    DRF的解析器和渲染器
    DRF的分页
    DRF 权限 频率
    DRF 版本 认证
    Django Rest Framework 视图和路由
    Serializers 序列化组件
    六、Java NIO 通道之间的数据传输
  • 原文地址:https://www.cnblogs.com/wangchunmeix/p/2972201.html
Copyright © 2011-2022 走看看