Object-oriented inheritance _ _ abstract class

Inherited:

A class can inherit another class, use the extends keyword such as:

public class Student extends Person{

}

如果一个类A继承自一个类B,A类称为子类或者叫做派生类。B类叫做父类或者是基类或者叫做超类。

子类可以继承父类中全部的属性以及方法。

注意:java allows only single inheritance, multiple inheritance is not allowed. But allows multi-layered inheritance.

即便是子类与父类之间也存在着访问权限的控制,子类中不能随意的访问父类中私有化的成员(属性以及方法)。

子类对象被创建之前,先创建父类的对象。

父类的静态块会优先被执行,然后执行子类的静态块,执行父类的构造块,父类的构造方法,子类的构造块,子类的构造方法。

Method overloading: overload
Methods rewrite: override

Rewrite occurs in the child and parent class, subclass refers to a method to rewrite the parent class, subclass requirements same method name and method name of the method of the parent class. The same parameter list, the return value should be the same type, but access to the subclass can not access smaller than the parent class.

Super Keyword:
1.强调是父类的属性或者是方法。

2.可以调用父类的构造方法

注意:If subclass constructor does not explicitly specify which one calls the parent class constructor, the default constructor calls the parent class without parameters.

When the father is not the no-argument constructor, the constructor of a subclass, you must explicitly specify a specific call to which a parameter constructor of the parent class.

super调用父类构造方法的语句,必须写在子类构造方法的首行。

注意:super does not mean that the parent object.

final keyword:
1.使用final修饰的变量即为常量,常量的值一旦被指定就不能被更改。

2.使用final修饰的类不能有子类。

3.使用final修饰的方法不能被子类重写。

Abstract class:

There is a java class to other classes devoted to as the parent class. This class is called an abstract class. Abstract class is modified to use abstract class.

Abstract methods:

The abstract modified method is called abstract methods.

注意:Abstract method does not write the specific implementation, do not write braces and braces code

Abstract class declaration and usage rules:
1.抽象类必须使用abstract进行修饰。

2.如果一个类中包含了至少一个的抽象方法,这个类必须声明为抽象类。

3.如果一个子类(不是抽象类)继承了一个抽象类,那么这个子类必须重写抽象类中全部的抽象方法。
Abstract syntax:
访问权限修饰符 abstract class 类名 【extends 类名】{
    属性
    方法
    抽象方法
}

注意:An abstract class can not create object

Specific application abstract class:

Template design pattern

访问权限修饰符 【final】 【static】 【abstract】 返回值类型 方法名称(【参数】){
}

Guess you like

Origin www.cnblogs.com/SunMoonSky/p/12370575.html