015-005-006

Basic Type Checking with instanceof

Easy

Problem Description

Basic Type Checking with instanceof

In this problem, you will create a program that reads an animal type and name from standard input, creates the corresponding object using the Animal class with Dog and Cat subclasses, checks its type using the instanceof operator, and displays the results.

Learning Objective: Understand how to check object type using the instanceof operator

Overview

Read an animal type (Dog or Cat) and a name from standard input, create the corresponding object, and check its type using instanceof.

Input Format

type (Dog or Cat)
name

Specifications

  • Define Animal class and its subclasses (Dog, Cat)
  • Create an object based on the input type
  • Check the type of the object with instanceof
  • Output the results

Output Format

{name} is Animal: true/false
{name} is Dog: true/false
{name} is Cat: true/false

Sample Input/Output

Input:

Dog
Pochi

Output:

Pochi is Animal: true
Pochi is Dog: true
Pochi is Cat: false

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up