Summary of inheritance

巴扎黑
Release: 2016-12-20 11:56:05
Original
1342 people have browsed it

Summary of inheritance

1. Benefits of inheritance:

1. If there is a lot of code in the subclass that is the same as in the parent class, inheritance can save a lot of code and reduce redundancy.

2. Inheritance is used to improve object-oriented programming ideas.

2. Inheritance format:

Access modifier class subclass name extends parent class name { }

3. The subclass inherits all the attributes and methods of the parent class, but the score is scored when the subclass calls the method of the parent class

                                                                  use using using using using using using         out out out through  ‐ off ‐ ‐ ‐ ‐ ‐‐ ‐‐ ‐‐ for Shared properties and methods

4. Rewriting

The meaning of rewriting: The behavior of classes with inheritance relationships in real life may be different, and rewriting imitates this phenomenon. 1 The condition of rewriting: 1. To achieve rewriting, it must be the existing method of the parent class;

2. The method of rewriting of the subclass must be the type, the number of parameters, the number of parameters, the number of parameters, and The parameters

                                                                                                  use using using   using               out out out ’s ’ ’s ’ ’ ’   ‐ ‐ ‐ ‐ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ 1.和 The only one that can be rewritten to the parent class is the type of access to the decorative character.

Access modifiers from large to small public ---à protected --à private

The difference between overwriting and overloading:

1. Overloading In the same class, overriding is between the parent class and the subclass

2. Overloading is a method with the same method name but different return value type or parameter type or number. Overriding means that the return value type, parameter type, number of parameters, and method name of the method of the subclass and the parent class are exactly the same.

Implementation of automatic transformation

Automatic transformation can only exist between parent class and child class, and the implementation of automatic transformation must have an inheritance relationship.式 The format of automatic transformation:

The name of the parent class name = new subclass constructor ();

The object obtained by automatic transformation is the object of the subclass, but the automatic transformation cannot reference the method defined by the subclass.

This defect can be overcome by forced transformation. Forced transformation format:

                                                                                                                                                                                                                                                                               ’’ name = new subclass constructor();

access Modifier return value type method name (parent class name parent class object name) {                                                                         Return value type           Method name (                                                                                                                Return value type method.

Polymorphism: Polymorphism is the uncertainty in the final result caused by method overloading, rewriting, inheritance, and automatic transformation.

Data types: Data types include basic data types and class data types (reference data types).

Basic data types:

型 byte byte type-128-127

Char character 16bit

int intersection 32bit

short short integer 16bit

Float single precision 32bit

long integer 64bit

double 64bit

64bit

Boolean true or false

Value transfer of basic data types

Reference data types: As long as the defined classes are reference data types, abstract class and interface are also reference data types, and arrays are also reference data types.

int [] I = new int[10];

Value passing

Value passing is suitable for basic data types and String class, (String class can also be passed by reference data), allocating stack memory

​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ Reference data type. Allocate stack memory and heap memory.

The login interface is improved (add pictures)

1. There are two ways to get the path of the picture

The first one: String url = "picture path"; Paths are divided into relative paths and absolute paths, and relative paths are generally used.

Second type: String.net.URL url = this.Class().getResource("Picture name"); This is to use the path of the current class to obtain the picture path, which is suitable for pictures and classes that exist in the same package.

2. Instantiate an image object using javax.swing.ImageIcon();

3. Instantiate a picture interface, and then add the picture interface to the container.


🎜
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template