Home > Java > javaTutorial > body text

Regaining the Basics of Java (6): Summary of Object-Oriented Basics

黄舟
Release: 2017-01-16 09:29:49
Original
1798 people have browsed it

Regain the basics of java (6): Summary of object-oriented basics

1. Understand the concepts of classes and objects

 类:其实就是一种基本数据类型       
 例如i的类是int类型       
 开发时定义的一个类,以后供自己使用   
 对象:我们把看到的一种事物看做一个对象,来进行研究   
 类和对象的关系:类是一个模板,把你要研究的对象所在的那个类别         
 进行定义,当做模板,然后在你要研究的对象时,对模板中的         
 你需要的函数进行调用,来实现你要研究的对象的具体功能. 
 一个标准的类包括:
 1、属性                  
 2、构造函数                  
 3、set(存)/get(取)函数                  
 4、普通方法
Copy after login

2. Define a class

class 类名{           }       类名的取名要遵守标示符的规则;首字母大写,若有多个字符每个首字母都大写
Copy after login

3. Creating and using objects

   使用new      类名  对象名=new 类名();
Copy after login

4. Member variables and local variables

 成员变量定义在函数外,类中;成员变量整个类中都可以使用;      
 局部变量定义在函数中,只有当前的类可以使用;       
 eg.public class Test {                   
 int num;    //属性,成员变量             
 public void show(){                   
 int num=10;    //局部变量                   
 System.out.print(num);}
Copy after login

//The value of num here is 10

    public static void main(String[] args) {                  
    Test t=new Test();                        
     t.show();                    
     System.out.println(t.num);
//这里的num的值为0 }
}
Copy after login

6 , Encapsulation

Function is an encapsulation of a piece of execution code; private Private encapsulation

7, Construction method

class  类名{              
public 类名(){              
}              
public 类名(形参){              
}    
}
Copy after login

8, this keyword

  1. If the parameter name is the same as the attribute name, the assignment will fail. Use this this to represent the current object

2. When calling a method inside a class, the previous This.

will be added automatically. 3. You can call the construction method of this class

The above is the content of Regaining the Basics of Java (6): Summary of Object-Oriented Basics. For more related content, please pay attention to PHP Chinese website (www.php.cn)!


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