Write a class using the following specifications and data type, access modifiers
ID: 3666533 • Letter: W
Question
Write a class using the following specifications and data type, access modifiers and return types as appropriate.
Nmae the class Person
instance variables are name of a data type Sring and age of a data type int.
default constructor using the default ""for String and 0 for int.
formal overloaded contructor accepting the formal parameters newName and newAge . and initializing the instance variables.
Method named printPerson which only prints the following 2 lines using xxx for the instance variable value.
This person's name is : xxx
This person's age is :xxx
Explanation / Answer
Class Person{
String name ;
int age;
Person(){
name ="";
age = 0;
Person(String newName , int newAge ){
name = newName;
age = newAge;
}
void printPerson(){
cout <<"This person's name is : "<<name ;
cout<<"This person's age is :"<<age;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.