Skip to content
Programming101
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programmingoneonone

HackerRank Java Method Overriding 2 (Super Keyword) solution

YASH PAL, 31 July 2024

In this HackerRank Java Method Overriding 2 (Super Keyword) problem in java programing language You are given a partially completed code in the editor. Modify the code so that the code prints the following text:

Hello, I am a motorcycle, I am a cycle with an engine.

My ancestor is a cycle who is a vehicle with pedals.

HackerRank Java Method Overriding 2 (Super Keyword) solution

HackerRank Java Method Overriding 2 (Super Keyword) problem solution.

import java.util.*;
import java.io.*;


class BiCycle
{
   String define_me()
   {
      return "a vehicel with pedals.";
   }
}

class MotorCycle extends BiCycle
{
   String define_me()
   {
      return "a cycle with an engine.";
   }
   
   MotorCycle()
   {
      
      
      System.out.println("Hello I am a motorcycle, I am "+ define_me());
      String temp=super.define_me();
      System.out.println("My ancestor is a cycle who is "+ temp );
   }
   
}
class Solution{
   public static void main(String []argh)
   {
      MotorCycle M=new MotorCycle();
   }
}

Second solution

import java.util.*;
import java.io.*;


class BiCycle{
    String define_me(){
        return "a vehicle with pedals.";
    }
}

class MotorCycle extends BiCycle{
    String define_me(){
        return "a cycle with an engine.";
    }
    
    MotorCycle(){
        System.out.println("Hello I am a motorcycle, I am "+ define_me());

        String temp=super.define_me();

        System.out.println("My ancestor is a cycle who is "+ temp );
    }
    
}
class Solution{
    public static void main(String []args){
        MotorCycle M=new MotorCycle();
    }
}
coding problems solutions Hackerrank Problems Solutions Java Programming Tutorials

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes