We need to create instances of an object using a constructor.
Problem Description: We will use Person class and create the instance of it using a constructor. Then accept the person’s information and print their details.
Algorithm:
- Step 1: Create a class named Person to store information of person (name and age).
- Step 2: Create the object of class and then input the information using getPersonDetails() method.
- Step 3: Then we will print the information using printDetails() method.
Program to illustrate the constructor initialization
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer