[Java] Classes and Objects

Classes and Objects

Java class mainly consists of two parts:memberwithmethod

Category is a set of abstract concepts.
The object is represented by a separate individual.
----------------------------------------------

The definition of a Person class :

public class Person {
	String name;
	int age;

	public void tell() {
		System.out.println("姓名"+ "、年龄:" + age);
	}
}

The Person class defines two variable name and Age, and then defines a tell () method is used to output the contents of the variable.
----------------------------------------------

Type of operation performed by instantiating objects :

public class Demo {
	public static void main(String[] args) {
		Person p = new Person();
		p.name = "张三";
		p.age = 18;
		p.tell();
	}
}

After completion of the definition of a class can not be directly used, but class describes a broad concept, the specific operation must be performed by the object.
We made instantiate an object of class Person keyword new, and variable assignment for the class, and implement the method call.

Published 38 original articles · won praise 4 · Views 833

Guess you like

Origin blog.csdn.net/Hide111/article/details/104973460