Java Inheritance--1

Source: Internet
Author: User





music

Package Text1;public class Instrument {//output playing instrument public void play () {System.out.println ("instrument");}}

Package Text1;public class Wind extends instrument {//output play windpublic void Play () {System.out.println ("Play Wind");} The output calls Wind's play2public void Play2 () {Wind p=new wind ();p. Play ();}

Package Text1;public Class Brass extends instrument {//output play brasspublic void Play () {System.out.println ("play Brass");} Output calls Wind's play2public void Play2 () {Brass b=new Brass (); B.play ();}}

Package Text1;public class Music {//Call Object I's Play method public static  void Turn (instrument i) {i.play ()} public static void Main (string[] args) {//TODO auto-generated method stub wind W=new wind ();//Call Wind method Turn (w); Brass b =new Brass ();//Call Brass method Turn (b);}}
















Java Inheritance--1

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.