Object-oriented learning of Java Tutorials (II.)

Source: Internet
Author: User

Learn to Program Java learning Object-oriented (ii) published, please visit by xuebiancheng8.com

The concepts of classes and objects, properties, and methods in object-oriented objects have been analyzed earlier. Let's learn how to define a class. For example, there is a student class, there are age, name and other attributes, there is a way to learn, eat.

The code is as follows:

public class person{

String name;

int age;

public void Study () {

System.out.println ("learning");

}

public void Eat () {

System.out.println ("being eaten");

}

}

The above defines a person class, the public class person

Public is open, class is a keyword, a class is defined, the person is the class name

String name;//defines the property name, which is a string

int age;//definition attribute age, type is int type

public void Study () {

System.out.println ("learning");

}

public void Eat () {

System.out.println ("being eaten");

}

The above respectively defines the study method and the Eat method, respectively printing is learning and is eating.

Please visit xuebiancheng8.com for details. URL is

Http://xuebiancheng8.com/play/goodgoodstudy_84_daydayup.html


Object-oriented learning of Java Tutorials (II.)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.