Java Marker Interfaces Explained

Day 9/100 – Java Practice Challenge 🚀 Continuing my #100DaysOfCode journey with another important Java concept. 🔹 Topic Covered: Marker Interfaces Marker interfaces are empty interfaces (no methods) used to “mark” a class. Based on this marker, Java or frameworks can change the behavior of objects. 💻 Practice Code: 🔸 Example Program class Marker { } class Student implements Marker { String name = "Niranjan"; } public class Main { public static void main(String[] args) { Student s = new Student(); if (s instanceof Marker) { System.out.println("Marker interface detected for: " + s.name); } else { System.out.println("No marker interface"); } } } 📌 Key Learnings: ✔️ Marker interfaces do not contain methods ✔️ Used as a tagging mechanism ✔️ Checked using instanceof ✔️ Examples: Serializable, Cloneable 🎯 Focus: Understanding how Java uses marker interfaces to control behavior without methods 🔥 Interview Insight: Marker interfaces are used to provide metadata and are commonly asked in Java interviews. #Java #100DaysOfCode #MarkerInterface #JavaDeveloper #Programming #LearningInPublic

To view or add a comment, sign in

Explore content categories