Java example code, how to use extends and implements in class package myjavaexample; public class MyJavaExample { private interface DoSomething { public void sound(); } private class Animal { public String voice= "Animal" ; public Animal() { } public Animal(String voice) { this .voice=voice; } } private class Pet extends Animal implements DoSomething { public Pet() { } public Pet(String voice) { super(voice); } public void sound() { System.out.println( this .voice); } } public void experiment() { Pet dog= new Pet(); dog.sound(); Pet cat= new Pet( "Miauww" ); cat.sound(); Pet bird= new Pet( "Cici" ); bird.sound(); } ...
Comments
Post a Comment