java language Create the inheritance relationship by doing base class People, derived class Student Modify the Student constructor method to receive data from the People class as an argument. In main modify the creation of student object using constructor to pass attributes of people and student Modify the ShowStudent method so that it displays the People data. In main it will not be necessary
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
java language
Create the inheritance relationship by doing base class People, derived class Student
Modify the Student constructor method to receive data from the People class as an argument.
In main modify the creation of student object using constructor to pass attributes of people and student
Modify the ShowStudent method so that it displays the People data. In main it will not be necessary
Program Approach:
- Step 1: Create People class
- Step 2: Create instance variable in People class firstName String, lastName String, age int.
- Step 3: Create showPeople() method to display firstName, lastName and age.
- Step 4: Create Student class and inherits People class
- Step 5: People class is base class and Student class is derived class after inheritance.
- Step 6: Create instance variable numId int, avg double
- Step 7: Create constructor and pass same name arguments in constructor
- Step 8: Call People (base class) instance variable in Student class constructor with super keyword.
- Step 9: Assign class variable value of constructor arguments with this keyword
- Step 10: Create showStudent() method and display numId and avg value
- Step 11: Create Student class object in main method and pass arguments value to constructor
- Step 12: Call showStudent() method in main
- Step 13: Display both class properties in Student class.
- Step 14: End of the program
Step by step
Solved in 5 steps with 3 images