Three main features of Java object-oriented
Packaging
For example, we want to describe the attributes of people, we can name,age the related attributes of people ... Encapsulated as a human person
Class so that we can implement the encapsulation from the basic data (attributes) to the class
We can also encapsulate some common methods into a class, as a tool class, such as the method of data format verification,
Time format conversion method, so that we can implement the encapsulation from the common method to the class
In some cases, our data structure is more complex, and the declaration of another class is also declared in a property in one class.
Or declare a collection of a class as a property
Class teacher{public String name; Teacher's name public Family family;//Family class list<student> students;//teacher name of the student collection }
In special cases, such data encapsulation is not enough, we also need to restrict access, such as the addition of private decoration
Can only be called inside the class, for example:
class bank{ private string money;//Deposit Number public string getmoney () { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;RETURN&NBSP;MONEY;//Bank personnel perform withdrawal operations } public void setmoney (String money) { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;THIS.MONEY&NBSP;=&NBSP;MONEY;//Bank personnel perform deposit operation } }
The above encapsulation is at the level of attributes and methods, there is a more interesting package form is the inner class, the rule is:
The member inner class can unconditionally access all member properties and member methods of the external class, including private and static members, which, in combination with inheritance, cleverly solves the problem of single-inheritance in Java:
public class External extends Father { private string exname; //Inner class class internal { private string inname; public void print () { system.out.println (Exname); fatherprint ()//direct access to the Father class printing method } } public void get () { System.out.println (Internal.class); } Public string getexname () { return exname; } public void setexname (String exname) { Exname = exname; } }
Inherited
Polymorphic
This article is from the "Qinguan" blog, make sure to keep this source http://11083953.blog.51cto.com/11073953/1732817
Java Object-Oriented understanding