Question
Important: Please, I need Answers Within 30 Minutes. A) Class UnderGrad is a subclass of Class Student. It introduces an instance variable major, defines a
Important: Please, I need Answers Within 30 Minutes.
A) Class UnderGrad is a subclass of Class Student. It introduces an instance variable major, defines a constructor to initialize all its instance variables when an object of this subclass is created, and overrides its toString method. Write the code for class UnderGrad accordingly.
public class Student {
private String name;
private int id;
public Student (String name, int num) {
this.name = name;
id = num;
}
...
public String toString() {
return "Name: " + name + "; Id: " + id;
}
}
public class Undergrad{
...
}
B)Assume that code in the try block below may throw an exception.
public int doIt ( ) {// a method
int n = 0;
try {
...// code that may throw an exception
n = 1;
return 0;
}
catch (ArithmeticException e ) {
...// some actions
n = 2;
}
finally {
...// some actions
n = 3;
}
}
In this method, a value is assigned to variable n for more than once. Show all the values that are assigned to n in the order in which they are assigned under each condition given below:
a.If no exception is thrown.
b.If an ArithmeticException is thrown.
c.If anArrayIndexOutOfBoundsExceptionis thrown.
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