Question
Use the Java hierarchy you posted in week 5 (corrected based on any feedback you may have received). Add a user-defined exception that can be
Use the Java hierarchy you posted in week 5 (corrected based on any feedback you may have received). Add a user-defined exception that can be thrown by one of the methods as part of the validation or error checking. The main method should then create an instance of the class and call the method in such a way that the exception is thrown (e.g. invalid input or state of the system).
The posted Code is below:
class Combo
{
public int s=0;
public void print_g()
{
System.out.println("I am the Combo of 1 & 2! "+s);
}
//overloading
public void print_g(int n){
System.out.println("Method overloading........ by passing integer:"+n);
}
public void overriding(){
System.out.println("Method inside Combo class.");
}
}
class Piece1 extends Combo
{
public int o=1;
public void print_for()
{
System.out.println("I am Piece 1 of the combo! "+o);
}
//method overriding
public void overriding(){
System.out.println("Method inside Piece1 class.");
}
}
/*class Piece2 extends Combo
{
public int t=2;
public void print_val()
{
System.out.println("I am Piece 2 of the combo! "+t);
}
}*/
public class Main
{
public static void main(String[] args)
{
//Piece2 g = new Piece2();
//g.print_g();
//overloading
//g.print_g(5);
Piece1 p1 = new Piece1();
//overloading
p1.print_g();
p1.print_g(5);
//overriding
p1.print_for();
p1.print_g();
p1.overriding();
//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