前言:
当前兄弟们对“java程序设计清华大学”都比较讲究,朋友们都想要学习一些“java程序设计清华大学”的相关文章。那么小编在网络上收集了一些关于“java程序设计清华大学””的相关文章,希望咱们能喜欢,你们快快来了解一下吧!分享兴趣,传播快乐,增长见闻,留下美好!
亲爱的您,这里是LearningYard学苑。今天小编为大家带来“学习知多少:java篇”,欢迎您的访问。
Share interests, spread happiness, increase knowledge, and leave a good legacy!
Dear you, this is The LearningYard Academy. Today Xiaobian brings you "Learn how much to know :Java chapter”, welcome your visit.
一、思维导图
一、 Mind mapping
二、java类
2、 Java Class
Java 中的类
Classes in Java
类可以看成是创建 Java 对象的模板。
A class can be seen as a template for creating Java objects.
创建一个简单的类来理解下 Java 中类的定义:
Create a simple class from the above diagram to understand the definition of a class in Java:
public class Dog { String breed; int size; String colour; int age; void eat() { } void run() { } void sleep(){ } void name(){ }}
一个类可以包含以下类型变量:
A class can contain the following type variables:
局部变量:在方法、构造方法或者语句块中定义的变量被称为局部变量。变量声明和初始化都是在方法中,方法结束后,变量就会自动销毁。
Local variables: Variables defined in methods, construction methods, or statement blocks are referred to as local variables. Variable declaration and initialization are both in the method, and after the method ends, the variable will be automatically destroyed.
成员变量:成员变量是定义在类中,方法体之外的变量。这种变量在创建对象的时候实例化。成员变量可以被类中方法、构造方法和特定类的语句块访问。
Member variables: Member variables are variables defined within a class, outside of the method body. This variable is instantiated when creating an object. Member variables can be accessed by methods in the class, construction methods, and statement blocks for specific classes.
类变量:类变量也声明在类中,方法体之外,但必须声明为 static 类型。
Class variables: Class variables are also declared within the class, outside the method body, but must be declared as static types.
一个类可以拥有多个方法,在上面的例子中:eat()、run()、sleep() 和 name() 都是 Dog 类的方法。
A class can have multiple methods, and in the above example, eat(), run(), sleep(), and name() are all methods of the Dog class.
构造方法
Construction method
每个类都有构造方法。如果没有显式地为类定义构造方法,Java 编译器将会为该类提供一个默认构造方法。
Each class has a construction method. If a constructor is not explicitly defined for a class, the Java compiler will provide a default constructor for that class.
在创建一个对象的时候,至少要调用一个构造方法。构造方法的名称必须与类同名,一个类可以
有多个构造方法。
When creating an object, at least one construction method must be called. The name of the construction method must have the same name as the class, and a class can have multiple construction methods.
下面是一个构造方法示例:
Here is an example of a construction method:
public class Puppy{ public Puppy(){ } public Puppy(String name){ // 这个构造器仅有一个参数:name }}
今天的分享就到这里了。
如果您对今天的文章有独特的想法,
欢迎给我们留言,
让我们相约明天。
祝您今天过得开心快乐!
That's all for today's sharing.
If you have a unique idea for today’s article,
please leave us a message,
and let us meet tomorrow.
I wish you a happy day !
本文由learningyard新学苑原创,如有侵权,请联系我们!
翻译来源于谷歌翻译
部分来源于
百度文库
清华大学出版《java程序设计基础》
编辑&排版|百味
审核|闫庆红
标签: #java程序设计清华大学