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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started