Concept explainers
i have a parent class called Person containing the name and ID number of students and i need to write the program for a child class named student that extends from the parent class and also adds two more attributes
below is a copy of my Parent class
public class Person
{
private String name;
private int id;
public Person( )
{
name = "not defined";
id = 0;
}
public Person(String newName, int newId )
{
name = newName;
id = newId;
}
public String getName( )
{
return name;
}
public int getId( )
{
return id;
}
public void setName(String newName)
{
name = newName;
}
public void setId(int newId)
{
id = newId;
}
public void set(String newName, int newId)
{
name = newName;
id = newId;
}
public String toString( )
{
return "Name = " + name + "ID is " + id;
}
}
Here I have defined the class named Student.
While defining the class I have used extend keyword to inherit the parent class Person.
Inside the class Student, I have defined 2 data members to record marks and the city of the student.
Next, I have created getters and setters for the defined attributes.
Then, I have created the constructor and inside the parameterized constructor I have called the constructor of Person using super().
In the end, I have overridden the toString() method, and inside the method, I have called the parent's toString() using the super keyword.
Step by stepSolved in 2 steps
- Java- Suppose that Vehicle is a class and Car is a new class that extends Vehicle. Write a description of which kind of assignments are permitted between Car and Vehicle variables.arrow_forwardConsider a class "Fan" with two integer data members, "state" (0/1 i.e. on or off) and "speed". 1. Write a parameterized Constructor for this class. 2. Write a member function "changeState( )" which behaves similar to pressing a button i.e. it should change the state of the fan. If it is off (0), calling the function should turn it on (1) and vice versa.. Multi Line Text.arrow_forwardPlease type the code for the following problems in Pythonarrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY