class Animal { void eat() { System.out.println("The animal eats food."); } } class Dog extends Animal { void bark() { System.out.println("The dog barks."); } } public class InheritanceExample { public static void main(String[] args) { Dog myDog = new Dog(); myDog.eat(); myDog.bark(); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter