实验课上第一次实现简单的接口

实验题目:

   

    1、定义矩形接口rect ,在接口中有计算面积area()、获取宽度getWidth()、获取高度getHeight()。继承接口rect实现矩形类Rectangle1.编写程序应用Rectangle1类。

 

 

 

 

 class Rectangle1 implements rect              // Rectangle1类 实现 接口rect .

{

       public  double height,width; //定义矩形的高 宽变量.

       public void  area()        //实现面积 计算方法.

       {    

              System.out.println ("This Rectangle's area is:" +this.width * this.height)  ;

       }
      

       public void  getWidth()        //取得矩形宽度.

       {

              System.out.println ("The Width is:" +this.width);       

       }

      
       public void  getHeight()       //取得矩形高度.

       {

              System.out.println ("The Height is:" +this.height);

       }

}
 

public class Re       //主类

{

       public static void main(String[] args)

       {

              Rectangle1 a=new Rectangle1();   //实例化.

              a.width=232;

              a.height=123;

              a.area();

              a.getWidth();

              a.getHeight();        

       }

}

 

interface rect  //接口类

{

       public void  area();

       public void  getWidth();

       public void  getHeight();     

}

 

 

  

    总结:这是第一次写接口,其实挺简单的(只是简单的实现题目要求而已),主要是看过没练过,真动起手来,还是有点慢。

 

   把第一次的贴出来,做自己的警示吧,刺激提高!

     

  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是一道光_

1分也是爱,鼓励鼓励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值