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). Submit your program as an attached .java file and post a screen shot to show that you have been able to successfully run that program.

The code is below:

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

class one_cls { public int s=0; //parent class method public void print() { System.out.println("Parent class method: G for geek "+s); } }

class two_cls extends one_cls { public int o=1; //overloading method public void print(int a) { //prints the message System.out.println("This method "+o+ " overloads the parent method with a parameter storing a value "+a); //calling the parent method super.print(); } }

class three_cls extends one_cls { public int t=2; //print method override method @Override public void print() { //calling the super class method super.print(); System.out.println("This function call overrides the parent method: "+t); } }

public class Main { public static void main(String[] args) { //creating object three_cls g = new three_cls(); two_cls a = new two_cls(); //calling the print method of three_cls g.print(); System.out.println(); //calling the print method of two_cls a.print(2); } }

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!