tubeshowcase●1,146,564 videos♡ My collection 0
← Learn to Code

Learn to Code05:02

Learn Java anonymous classes in 5 minutes! 🕵️‍♂️

Bro Code ↗

From the creator

#java #javatutorial #javacourse public class Main { public static void main(String[] args) { // Anonymous class = A class that doesn't have a name. Cannot be reused. // Add custom behavior without having to create a new class. // Often used for one time uses (TimerTask, Runnable, callbacks) Dog dog1 = new Dog(); Dog dog2 = new Dog(){ @Override void speak(){ System.out.println("Scooby Doo says *Ruh Roh*"); } }; dog1.speak(); dog2.speak(); } } public class Dog { void speak(){ System.out.println("The dog goes *woof*"); } }

Published 2024-12-19 · Watch on YouTube ↗
Availability and playback restrictions are controlled by the original channel.

Keep exploring Learn to Code