Question: Use the Java hierarchy you posted in week 3 (corrected based on any feedback you may have received) add one overriding method and one overloading.

Use the Java hierarchy you posted in week 3 (corrected based on any feedback you may have received) add one overriding method and one overloading. The main method should create an instance of the class and demonstrate correct functionality of the overriding and overloading methods.

The code is posted below:

import java.util.*;

import java.lang.*;

import java.io.*;

//parent class

class Combo

{

public int s=0;

public void print_g()

{

System.out.println("I am the Combo of 1 & 2! "+s);

}

}

//inheriting class Combo

class Piece1 extends Combo

{

public int o=1;

public void print_for()

{

System.out.println("I am Piece 1 of the combo! "+o);

}

}

//inheriting class Combo

class Piece2 extends Combo

{

public int t=2;

public void print_val()

{

System.out.println("I am Piece 2 of the combo! "+t);

}

}

// Driver class

public class Main

{

public static void main(String[] args)

{

//creating object

Piece2 g = new Piece2();

g.print_g();

//creating object

Piece1 t = new Piece1();

//calling function

t.print_for();

//calling function

g.print_val();

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!