014-008-006

Verify Object Class Inheritance

Easy

Problem Description

Verify Object class inheritance

In this problem, you will read an integer n from standard input, create n instances of the Sample class, and use the instanceof operator and getClass().getName() to verify the Object class inheritance relationship for each instance, displaying the results to standard output.

Learning Objective: Understand that all classes implicitly inherit from Object class

Overview

Create a program that generates the number of Sample instances specified by Scanner input and confirms that each instance inherits from Object class.

Specifications

  • Read integer n from standard input using Scanner
  • Define Sample class (no extends)
  • Loop n times, creating a Sample instance each iteration
  • Use instanceof operator to confirm each is an Object instance
  • Get class name with getClass().getName()
  • Print each instance's result in the specified format

Input Format

n
  • n: number of instances to create (positive integer)

Output Format

Instance 1: Is Object: true, Class: Sample
Instance 2: Is Object: true, Class: Sample
...

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