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