0% found this document useful (0 votes)
12 views1 page

Engineer Class in OOP Java

The document defines an 'Engineer' class that extends the 'Person' class, inheriting its fields and methods. It includes a constructor that initializes the Engineer's salary along with inherited attributes. The 'printInfo' method is overridden to include the Engineer's salary in the output.

Uploaded by

lalosamal666
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

Engineer Class in OOP Java

The document defines an 'Engineer' class that extends the 'Person' class, inheriting its fields and methods. It includes a constructor that initializes the Engineer's salary along with inherited attributes. The 'printInfo' method is overridden to include the Engineer's salary in the output.

Uploaded by

lalosamal666
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// Package declaration: This class is part of the 'oop' package

package oop;

// 'Engineer' class extends the 'Person' class, meaning it inherits all fields and
methods from 'Person'
public class Engineer extends Person {
// Instance variable specific to Engineer
double salary; // Engineer's salary

// Constructor for the Engineer class


// Calls the constructor of the superclass (Person) using 'super' and sets the
salary
public Engineer(String name, String address, String major, int age, String
gender, double salary) {
super(name, address, major, age, gender); // Call to the parent class
(Person) constructor
[Link] = salary; // Set the salary field for the
Engineer
}

// Override the printInfo method to add salary to the printed information


@Override
public void printInfo() {
[Link](); // Call the superclass version
of printInfo to print basic info
[Link]("Salary: " + salary); // Print the Engineer's salary
}
}

You might also like