class Animal {
public void makeSound() {
System.out.println("Animals make sound");
}
}
class Dog extends Animal {
public void makeSound() {
System.out.println("Dogs bark");
}
}
public class Main {
public static void main(String[] args) {
Animal myAnimal = new Animal();
Animal myDog = new Dog();
myAnimal.makeSound();
myDog.makeSound();
}
}
class Animal {
public void makeSound() {
System. out.println("Animals make sound");
}
}
class Dog extends Animal {
public void makeSound() {
System.out.println("Dogs bark");
}
}
class Cat extends Animal {
public void makeSound() {
System.out.println("Cats meow");
}
}
public class Main {
public static void main(String[] args) {
Animal myAnimal = new Animal();
Animal myDog = new Dog();
Animal myCat = new Cat();
myAnimal.makeSound();
myDog..makeSound();
myCat.makeSound();
}
}
public class OuterClass {
private int x = 10;
public class InnerClass {
public int getX() {
return x;
}
}
public static void main(String[] args) {
OuterClass outer = new OuterClass();
OuterClass.InnerClass inner = outer.new InnerClass();
System.out.println(inner.getX());
}
}
public class Main {
interface Message {
String greet();
}
public void displayMessage(Message m) {
System.out.println(m.greet());
}
public static void main(String[] args) {
Main obj = new Main();
obj.displayMessage(new Message() {
public String greet() {
return "Hello";
}
});
}
}