. Implement the following class inheritance relationships, and write Music classes to test these classes.
Public class Instrument { publicvoid play () { System.out.println ("Play instrument" ); }}
public class wind extends instrument { public Span style= "color: #0000ff;" >void play () {System.out.println ( "Play Wind" ); public void Play2 () {System.out.println ( "Calls Wind's Play2"
public class Brass "extends instrument { public Span style= "color: #0000ff;" >void play () {System.out.println ( "Play brass" ); public void Play2 () {System.out.println ( "Calls brass Play2"
public class Music { static void tune (instrument i) {i.pl Ay (); public static void main (String args[]) {wind W = new< /span> Wind (); Tune (w); Tune ( new Brass ()); }}
Write a Java application that consists of 3 classes: class a ,classB , and main class E . Which
Class B is a subclass of class A , new member variables and member methods are added to subclass B , and the parent class is hidden
A member variable and overrides a member method of parent Class A. In main class E , in the main method, create class B
object and assign it to the object A of the parent class A , use the On Transformation object a to test some of the features of the object being transformed.
Public class A { int a1=5; Public void MA () { System.out.println ("a.ma");} }
public class B extends A { int b1=6; int a1=7; public void MB () {System.out.println ( "B.MB" ); public void MA () {System.out.println ( "b.ma" ); } }
Public class Tseta { publicstaticvoid main (string[] args) { b b=new B (); A=b; System.out.println ("b.a1=" +b.a1); System.out.println ("b.b1=" +b.b1); B.ma (); B.MB (); System.out.println ("a.a1=" +a.a1); A.ma (); }}
Write a Java application that consists of 3 classes:theMonkey class,thepeople class, and the main class
E.
Public class Monkey { private String s; Public String GetS () { return s; } Public void sets (String s) { this. s = s; } Public void speak () { System.out.println ("babbling ...");} }
public class people "extends Monkey { public void Speak () {System.out.println (" Sample, good! It's going to talk! "); public void think () {System.out.println () Don't talk! Think hard! "); } }
Public class E { publicstaticvoid main (string[] args) { Monkey m=New Monkey (); M.speak (); People p=new people (); P.speak (); P.think (); }}
Java one, inheritance-related