Hackerrank 30 days of code Java Solution: Day 12: Inheritance

The next problem is based on Inheritance. Inheritance is adapting the hierarchy of classes. The classes that inherits are called subclasses and the class inherited is called superclass.

You can read in detail what exactly is inheritance in Object Oriented Programming language from here

The few important concepts which you must be aware of while going through the concept of inheritance are:

  • Different types of Inheritance java supports
  • Why java doesn’t support multiple inheritance?
  • Concepts of superclass and subclass. Use of “super” keyword .
  • What are interfaces and what are abstract classes  ? , etc….

So now lets jump to the task which we need to perform here today:


You are given two classes, Person and Student, where Person is the base class and Student is the derived class. Completed code for Person and a declaration for Student are provided for you in the editor. Observe that Studentinherits all the properties of Person.

Complete the Student class by writing the following:

  • Student class constructor, which has  parameters:
    1. A string, .
    2. A string, .
    3. An integer, .
    4. An integer array (or vector) of test scores, .
  • char calculate() method that calculates a Student object’s average and returns the grade character representative of their calculated average:

Sample Input

Sample Output

So here the Solution you have landed here for..

Thanks for the visit checkout the day 13 tutorial as well.. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *