Chicken dishes learn java: object-oriented emphasis summary

              ***小菜鸡学java:面向对象重点总结***
              *main方法是一个程序的入口*
 java语言的基本元素:类(class) 和  对象
 类的成员之一:属性(成员变量)
 类的成员之二:方法---c语言中的函数
 可以理解为:类 = 汽车设计图   /  对象:实实在在的汽车
 面向对象程序设计的重点是类的设计
 定义类其实是定义类中的成员(属性,方法)
                           **类的语法格式**:
 **修饰符(pubilc) class 类名{
                                属性声明**(类成员性可以先声 明不用初始化,
                              **类成员变量**有**默认值**)**
                                方法声明**(方法名字有多个单词时,
                                                    第一个单词首字母小写,其他单词首字母大写)**
                                                          }

** create and use objects
* class name object name = new class name ();
Example: Person the p-Person = new ();
// declare a Person type of variable, the variable name p, new Person is an instance of the Person class
objects name attribute.
object method name (parameter).
for the use of nothing more than objects: class method of operating variables, call the class.
***** a
classes may have a plurality of objects

Attribute Syntax:
modifier (private // public) type (base type) attribute name = initial value;
Private: This attribute can only be accessed by a method in the class;
public: a method other than the class can be accessed;

Variables into: member variables / local variables
in vitro methods, variables declared within the class member variable called (can be accessed throughout the class, there is a default initialization value, there modifier)
referred variables declared within method body local variables (no modifier, no default value must be initialized, only be used in the process)

Member variables into an instance variable (not in a static modification, in order to use instantiated)
and class variables (with static modification, can be directly instantiated objects using the class is not required) class name. Name

Method Format:
modifier return type method name (parameter) {
method body statement
}
method invoked will be executed only
method which can call the method, the method can not be defined within the method;

**匿名对象:**不用实例化对象,直接调用,一次
**new 类名().方法名();**
方法可以用匿名对象做参数

static methods can not access the non-static properties;

Summary: Class 1 dedicated design, i.e. the members of the design categories: Property, Method
2. The class is instantiated to create objects of classes (for example: P = the Person new new the Person ();)
3. object properties, object. The method of execution

Published an original article · won praise 0 · Views 40

Guess you like

Origin blog.csdn.net/lllhhffh/article/details/104055149