Explanation of Solution
a.
Given line:
Person p1 = new Student ();
Explanation:
The “Person” and “Student” are two classes. The class “Student” is the derived class and “Person” is the base class...
Explanation of Solution
b.
Given line:
Person p2 = new Undergraduate ();
Explanation:
The “Person” and “Undergraduate” are two classes...
Explanation of Solution
c.
Given line:
Student s1 = new Person ();
Explanation:
The “Person” and “Student” are two classes. The class “Student” is the derived class and “Person” is the base class...
Explanation of Solution
d.
Given line:
Student s2 = new Undergraduate ();
Explanation:
The “Undergraduate” and “Student” are two classes. The class “Undergraduate” is extend from the “Student” class...
Explanation of Solution
e.
Given line:
Undergraduate ug1 = new Person ();
Explanation:
The “Undergraduate” and “Person” are two classes. The class “Undergraduate” is extend from the “Student...
Explanation of Solution
f.
Given line:
Undergraduate ug2 = new Student ();
Explanation:
The “Undergraduate” and “Person” are two classes. The class “Undergraduate” is extend from the “Student...
g.
“Object” class:
All classes in Java inherit from the “Object” class.
- • Directly and indirectly all classes are inherited from the “Object”class.
- • Some of the basic methods of the “Object” class are listed below:
- ○ clone()
- ○ toString()
- ○ equals()
The above methods are automatically created in java when a class is created.
h.
“Object” class:
All classes in Java inherit from the “Object” class.
- • Directly and indirectly all classes are inherited from the “Object”class.
- • Some of the basic methods of the “Object” class are listed below:
- ○ clone()
- ○ toString()
- ○ equals()
The above methods are automatically created in java when a class is created.
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
- Describe the scope of class.arrow_forwardDefine the struct studentType to implement the basic properties of a student. Define the class studentType with the same components as the struct studentType, and add member functions to manipulate the data members. (Note that the data members of the class studentType must be private.) Write a program to illustrate how to use the class studentType. Struct studentType: struct studentType { string firstName; string lastName; char courseGrade; int testScore; int programmingScore; double GPA; }; An example of the program is shown below: Name: Sara Spilner Grade: A Test score: 89 Programming score: 92 GPA: 3.57 *************** c++ code please This is the code I have but I keep getting error #include<iostream> using namespace std; class studentType { private: string firstName; string lastName; char courseGrade; int testScore; int programmingScore; double GPA; public: studentType(string f, string l, char CG, int TS, int PS, double gpa) { cout<<"Name:…arrow_forwardPART I: Given the following UML diagram. Answer the following questions PCRTest - newNum: int //-- auto-increment patientName: String previousResult: int //-- should be less than 35 - currentResult: int //-- should be less than 35 + PCRTest (patientName: String, previousResult: int) +setcurrentResult (int r):void +getcurrentResult () : int +isRecovered () : boolean +tostring () : String + GenerateCode (): String //-- explained in part III Question PCRTest as weir as the constructor and the setter and getter of the currentResult. Note that: • The attribute newNum is incremented when a PCRTest object is created. It represents the total ): Implement all the data fields represented in the UML diagram of the class number of tests. • The constructor accepts the patient's name and the previous test result. The value of previousResult and currentResult should be between 0 and 35. • The method setcurrentResult(int r) assigns the value r to the currentResult attribute. The method…arrow_forward
- Please written by computer source java codearrow_forwardProblem C Write a class called Name that has one instance variable to store the full name of a person. A name can have multiple words, separated by single spaces. The only non-letter characters in a name will be spaces or -. The class has one constructor that takes a parameter to initialize the instance variable. However, the parameter string could have spaces at either ends and the constructor must trim the extra spaces before assigning it to the instance variable. The class has the following methods. public String getName () Gets the name string. public int consonants() Gețs the number of consonants in the name. A consonant is any character that is not a vowel, the space or -. For this problem assume thearrow_forwardChapter 9 defined the struct studentTypeto implement the basic properties of a student. Define the class studentType with the same components as the struct studentType, and add member functions to manipulate the data members. (Note that the data members of the class studentType must be private.) Write a program to illustrate how to use the class studentType. Struct studentType: struct studentType { string firstName; string lastName; char courseGrade; int testScore; int programmingScore; double GPA; }; An example of the program is shown below: Name: Sara Spilner Grade: A Test score: 89 Programming score: 92 GPA: 3.57 ***************arrow_forward
- In this exercise, you have to perform composition between the Toyota class and its Engine! Problem Statement# You have to create a Toyota class which inherits from a Car class, and is composed of an Engine Note: You already know that in such a composition relation, the oyota class will be res ible for Engine's lifetime. Consider this diagram for reference Car - id: int model: String - color: String + carFeatures(): void +setModel(): void + setColor(): void Toyota ToyotaEngine **** start): void stop): void . ..... + setStart(): void Part of- Car, Toyota and ToyotaEngine: Class Representation You should implement the Toyota class as the child class of the Car. It should have an instance of ToyotaEngine and a setStart() function which in turn calls the start () function of the ToyotaEngine class. The start () and stop () functions of ToyotaEngine class simply print out on screen that the engine has been started/stopped.arrow_forwardList the privacy principles regarding public base class and private base class and their derived classes.arrow_forwardWhy can't a derived class variable be assigned a base class object?arrow_forward
- Explain the difference between a sub-class and a super-class.arrow_forwardSelect the answer that best describes the following statements: 1. When a reference type has yet to be instantiated, it contains a null value. II. Association is a specific type of Composition. O Only statement I is true Only statement II is true Both statements I and II are true Both statements I and II are falsearrow_forwardChapter 9 defined the struct studentType to implement the basic properties of a student. Define the class studentType with the same components as the struct studentType, and add member functions to manipulate the data members. (Note that the data members of the class studentTypemust be private.) Write a program to illustrate how to use the class studentType. Struct studentType: struct studentType { string firstName; string lastName; char courseGrade; int testScore; int programmingScore; double GPA; }; An example of the program is shown below: Name: Sara Spilner Grade: A Test score: 89 Programming score: 92 GPA: 3.57 ***************arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,