Multilevel Inheritance Implementation

Create a series of classes to demonstrate multilevel inheritance.

Explanation:

Create three classes to illustrate multilevel inheritance.

  • GrandFather: This class should have a parameterized constructor and an attribute grandFatherName.
  • Father: This class inherits from GrandFather. It should have a parameterized constructor with an additional argument for fatherName.
  • Son: This class inherits from Father. It should have a parameterized constructor with an additional argument sonName, and it must include a method printName to display sonName, fatherName, and grandFatherName in a specific format.

Input:

# No specific input format since this is about class and method creation

Output:

Saurabh Ramesh Suresh

Example:

Create an object of the Son class and pass: sonName as 'Saurabh', fatherName as 'Ramesh', and grandFatherName as 'Suresh'. Then call the printName method.

Constraints:

  • The constructor must initialize the attributes correctly in each class.
  • The method printName should output the names in the specified format.

Note:

The objective is to showcase inheritance and class design rather than standard input-output operations.

Be the first one to answer
Add answer anonymously...
SAP Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter