Inheritance and polymorphism of Java

Source: Internet
Author: User

1. Inheritance

Create Pet Parent class public class pet {private string name;private int      age;private int  health;private string love;public pet () {// System.out.println ("Parent class no parameter construction method");} Public pet (string name,int age,int health,string love) {this.name   =    name;this.age    =    age;this.health =  Health;this.love   =   love;//system.out.println ("Parent class has a constructor method");} Public string getname ()  {return name;} Public void setname (String name)  {this.name = name;} Public int getage ()  {return age;} Public void setage (Int age)  {this.age = age;} Public int gethealth ()  {return health;} Public void sethealth (Int health)  {this.health = health;} Public string getlove ()  {return love;} Public void setlove (String love)  {this.love = love;} Public void print () {System.out.println (name+ "\ t" +age+ "\ T" +health+ "\ T" +love);} Public void shout () {System.out.println ("Pet's cry! ");}}

2. polymorphic


This article is from the "Advanced Technology" blog, so be sure to keep this source http://vipnoon.blog.51cto.com/7589908/1792861

Inheritance and polymorphism of Java

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.