Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    Java instanceof Operator

    Java Programming Tutorials


    The Java instanceof Operator is used to determining whether this object belongs to this particular (class or subclass or interface) or not.

    This operator gives the boolean values such as true or false. If it relates to a specific class, then it returns true as output. Otherwise, it returns false as output.

    Syntax:

    object-reference instanceof type;

    Program to Show Downcasting with instanceof Operator

    Example:

    class Company {}
    
    public class Employee extends Company {
        public void check() {
            System.out.println("Success.");
        }
    
        public static void view(Company c) {
            if (c instanceof Employee) {
                Employee b1 = (Employee) c;
                b1.check();
            }
        }
    
        public static void main(String[] args) {
            Company c = new Employee();
            Employee.view(c);
        }
    }

    Output:

    Success.


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.