Class Object Encapsulation

Source: Internet
Author: User

Public class demo2

{

Public static void main (string [] ARGs ){

Animal duck = new animal ();

Duck. Eye = 2;

Duck. Foot = 2;

Duck. color = "black ";

Duck. content = "scream ";

Duck. See ();

System. Out. Print ("duck Club ");

Duck. Call ();

}

/* Animal duck;

Dunk = new animal ();*/

}

Class animal

{

Int eye;

Int foot;

String color;

String content;

Public void see (){

System. Out. Print (color );

}

Public void call (){

System. Out. Print (content );

}

}

Three major features of Java: encapsulation of polymorphism inheritance

Class is to generalize (encapsulate) a class of similar things. For example, an animal class can define class animal.

What will an animal do with the color (attribute) of its eyes, feet, and hairs (method)

When something in a class is called, an animal, such as a duck, is embodied (the duck can "inherit" attributes and methods in the animal class)

We can start with animal duck, and then new or new.

The program output result above: the black duck will be called.

This article is from the "11578233" blog, please be sure to keep this source http://11588233.blog.51cto.com/11578233/1774287

Class Object Encapsulation

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.