interface Speaker { void speak(); int age = 3; } public class Inherit { abstract class Dog implements Speaker { protected String name; } class MyDog extends Dog { MyDog() { name = "Lassie"; } public void speak() { System.out.println( "My name is " + name); System.out.println( "My age is " + age); } } Inherit() { new MyDog().speak(); } public static void main(String[] args) { new Inherit(); } }
interface Speaker { void speak(); } public class Inherit { class Dog implements Speaker { public void speak() { System.out.println("Woof!"); } } class Cat implements Speaker { public void speak() { System.out.println("Meow!"); } } Inherit() { Speaker c = new Dog(); Speaker d = new Cat(); c.speak(); d.speak(); } public static void main(String[] args) { new Inherit(); } }
public class OuterClass { static class InnerClass {