Day1

1.java程序基本结构:

class helloworld{
    public static void main(String[] args){
        //...........
    }
}

2.对象是现实世界实体的抽象。对象具有字段(变量)和方法(函数)。

3.类是很多独立对象拥有的相同点的集合(原文:你会经常发现很多独立对象都属于相同的类型)。

class Bicycle{
  int speed = 0;
  //............

  void speedUp(int i){
      speed  = speed + i;
  }
  //..............  
}

class helloworld{
    public static void main(String[] args){
      Bicycle bike = new Bicycle();

      bike.speedUp(10);
  }
}

4.类的继承:一个类从其他类中继承共同的状态(变量)和行为(方法)

  允许每个类有一个直接超类(父类),允许每个超类有数量不限的子类

class MountainBike extends Bicycle{
    /............................
}
inherit

5.接口:对象中的字段并不与外界直接接触,而是通过接口——即 方法。

  所以,接口是一组具有空方法体的方法

//定义
interface Bicycle{
  void speedUp(int i);
  void changeGear(int n);
  /..................
}

//实现
class ACMEBicycle implements Bicycle{
  //.....................
}
interface

6.包是相关类和接口的名称空间,类似于文件夹。

原文地址:https://www.cnblogs.com/lizhenxin/p/5857723.html