Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Learn INTERFACES in 6 minutes! 📋
Play lesson

Java tutorial for beginners ☕ - Learn INTERFACES in 6 minutes! 📋

5.0 (4)
40 learners

What you'll learn

This course includes

  • 12 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

#java #javatutorial #javacourse public class Main { public static void main(String[] args) { // Interface = A blueprint for a class that specifies a set of abstract methods // that implementing classes MUST define. // Supports multiple inheritance-like behavior. Rabbit rabbit = new Rabbit(); Hawk hawk = new Hawk(); Fish fish = new Fish(); rabbit.flee(); hawk.hunt(); fish.flee(); fish.hunt(); } } public interface Prey { void flee(); } public interface Predator { void hunt(); } public class Rabbit implements Prey{ @Override public void flee(){ System.out.println("*The rabbit is running away*"); } } public class Hawk implements Predator{ @Override public void hunt(){ System.out.println("*The hawk is hunting*"); } } public class Fish implements Prey, Predator{ @Override public void flee(){ System.out.println("*The fish is swimming away*"); } @Override public void hunt(){ System.out.println("*The fish is hunting*"); } }

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere