Java总结3

                                 第八章

一、面向对象的特性:封装,继承,多态

1、封装

  封装性是通过访问控制修饰符来限定应用程序内文件的访问级别的

  访问级别:public:共有的

            Protected:受保护

            Default:默认

            Private:私有的

例:public class Car{

       //对属性的封装

       private String brand

       private double length

       private double width

       private int seats=5

       public String getBrand(){

          return brand;

       }

       public void setBrandString brand{

       This.brand=brand;

       }

      public String getLength(){

          return length;

       }

       public void setLengthdouble  brand{

       This.length=length;

       } 

      public String getWidth(){

          return windth;

       }

       public void setWindthdouble width{

       This.width=width;

       }

       Public  int getSeats(){

          Return seats;}

}

 

2Output output=new Output();

2、继承

继承是通过extend来实现的

A   public class  A{

            Public  void showA(){

              System.out.printlna

      }

}

b  

Public class  B   extends  A{

        Public  void showB(){

              System.out.printlnb

      }

Public static  void   mainString【】args{

B b=new B();

b.showA();

b.showB();

}

 }

3、多态

(1)方法重载

(2)方法重写

4、Java中的类

(1)类

[修饰符] class类名[extends类名][implement 接口名]{

   <类的成员变量说明>

   <定义类的方法 >

}

(2)类的方法

     [修饰符]返回类型 方法名 ([参数]{

       方法体

}

abstract修饰的方法是抽象类

            

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值