0% found this document useful (0 votes)
4 views26 pages

Java Week8

The document outlines a Java programming assignment focused on email validation and meeting duration scheduling. It includes problem statements, input/output formats, and exception handling requirements, specifically detailing custom exceptions for invalid email formats and meeting durations. Sample code snippets and test cases are provided to guide implementation.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views26 pages

Java Week8

The document outlines a Java programming assignment focused on email validation and meeting duration scheduling. It includes problem statements, input/output formats, and exception handling requirements, specifically detailing custom exceptions for invalid email formats and meeting durations. Sample code snippets and test cases are provided to guide implementation.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

17 Rajalakshmi Engineering College

7
01

01

01
10

01

01

01
0
10

10

10

10
Name: Arul Amudhan G Scan to verify results
24

24

24

24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 3
Batch: 2028
Degree: B.E - IT
7

17

17
01

01
10

0
2024_28_III_OOPS Using Java Lab
01

01

01
00
10

10

10
1
24

24

24

24
2028_REC_OOPS using Java_Week 8_Q1

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
7

7
01

01

01

01
Write a program to validate the email address and display suitable
01

01

01

01
10

10

10

exceptions if there is any mistake. 10


24

24

24

24

Create 3 custom exception classes as below


DotExceptionAtTheRateExceptionDomainException
A typical email address should have a " . " character, and a "@" character,
and also the domain name should be valid. Valid domain names for
practice be 'in', 'com', 'net', or 'biz'.

Display Invalid Dot usage, Invalid @ usage, or Invalid Domain message


based on email id.
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10

Get the email address from the user, validate the email by checking the
24

24

24

24
above-mentioned criteria, and print the validity status of the input email
17

7
01

01

01
address.
10

01

01

01
0
10

10

10

10
24

24

24

24
Input Format
The first line of input contains the email to be validated.
Output Format
The output prints a Valid email address or an Invalid email address along with
the suitable exception

If email ends with . or contains not exactly one . after @, it throws:

DotException: Invalid Dot usage


7

17

17
01

01
10

0
01

01

01
Invalid email address
00
10

10

10
1
24

24

24

24
If @ appears not exactly once, it throws:

AtTheRateException: Invalid @ usage

Invalid email address


7

7
01

01

01

01
01

01

01

01
10

10

10

If the part after the last dot is not among accepted domains: 10
24

24

24

24

DomainException: Invalid Domain

Invalid email address

If all conditions satisfied then print:


7

7
01

01

01

Valid email address


10
01

01

01

0
10

10

10

10
24

24

24

24
17

7
01

01

01
10

01

01

01
0
10

10

10

10
Refer to the sample input and output for format specifications.
24

24

24

24
Sample Test Case
Input: sample@[Link]
Output: Valid email address
Answer
import [Link];

class DotException extends Exception{


public DotException(String message){
7

17

17
01

01
10

0
super(message);
01

01

01
00
10

10

10
}
1
24

24

24

24
}

class AtTheRateException extends Exception{


public AtTheRateException(String message){
super(message);
}
}

class DomainException extends Exception{


public DomainException(String message){
super(message);
7

7
01

01

01

01
}
01

01

01

01
10

10

10

10
}
24

24

24

24

public class Main{


public static void validateEmail(String email) throws DomainException,
AtTheRateException, DotException{
if([Link]("@") || [Link]("@") || [Link]("@@")){
throw new AtTheRateException("Invalid @ usage");
}

int atIndex = [Link]('@');


if(atIndex == -1 || atIndex != [Link]('@')){
throw new AtTheRateException("Invalid @ usage");
7

7
01

01

01

1
10

}
01

01

01

0
10

10

10

10
24

24

24

24
if([Link](".") || [Link](".") || [Link]("..") ||
17

7
01

01

01
[Link](".@") || [Link]("@.")){
10

01

01

01
0

throw new DotException("Invalid Dot usage");


10

10

10

10
}
24

24

24

24
if([Link]('.', atIndex) == -1){
throw new DotException("Invalid Dot usage");
}

int lastDotIndex = [Link](".");


String domain = [Link](lastDotIndex+1);

if( !([Link]("com") || [Link]("in") || [Link]("net") ||


[Link]("biz"))){
7

17

17
01

01
throw new DomainException("Invalid Domain");
10

0
01

01

01
00

}
10

10

10
1

}
24

24

24

24
public static void main(String args[]){
Scanner scanner = new Scanner ([Link]);
String email = [Link]();

try{
validateEmail(email);
[Link]("Valid email address");
}
catch(DotException e){
7

7
01

01

01

01
[Link]([Link]().getSimpleName() + ": " + [Link]());
01

01

01

01
[Link]("Invalid email address");
10

10

10

} 10
24

24

24

24
catch(AtTheRateException e){
[Link]([Link]().getSimpleName() + ": " + [Link]());
[Link]("Invalid email address");
}
catch(DomainException e){
[Link]([Link]().getSimpleName() + ": " + [Link]());
[Link]("Invalid email address");
}
[Link]();
}
7

7
01

01

01

}
10
01

01

01

0
10

10

10

10
24

24

24

24
24 24 24 24
10 10 10 10
01 01 01 0 10
01 01 01
7 7 7 17
Status : Correct

24 24 24 24
10 10 1 00 10
01 01 10 01
01 01 01
7 7 17 7

24 24 24 24
10 10 10 10
01 01 01 01
01 01 01 01
7 7 7 7

24 24 24 24
10 10 10 10
Marks : 10/10

0 10 01 01 01
1 01 0 01
7 7 17 7
17 Rajalakshmi Engineering College

7
01

01

01
10

01

01

01
0
10

10

10

10
Name: Arul Amudhan G Scan to verify results
24

24

24

24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 3
Batch: 2028
Degree: B.E - IT
7

17

17
01

01
10

0
2024_28_III_OOPS Using Java Lab
01

01

01
00
10

10

10
1
24

24

24

24
2028_REC_OOPS using Java_Week 8_Q2

Attempt : 1
Total Mark : 10
Marks Obtained : 0

Section 1 : Coding

1. Problem Statement
7

7
01

01

01

01
Elsa, a busy professional, is using a scheduling application to plan her
01

01

01

01
10

10

10

meetings efficiently. The application requires users to input meeting 10


24

24

24

24
durations in minutes, ensuring that the duration is a positive integer and
does not exceed 240 minutes (4 hours). Elsa needs a program to assist her
in scheduling meetings securely with proper exception handling.

Create a Java class named [Link] a custom


exception:InvalidDurationException for invalid meeting duration
[Link] the main method to interactively take user input for a
meeting [Link] the validateMeetingDuration method to
validate the meeting duration based on the specified rules and throw a
custom exception if the validation [Link] appropriate success or error
7

7
01

01

01

1
10

messages based on the meeting duration.


01

01

01

0
10

10

10

10
24

24

24

24
Implement a custom exception, InvalidDurationException, to handle cases
17

7
01

01

01
where the entered meeting duration does not meet the specified criteria.
10

01

01

01
0
10

10

10

10
24

24

24

24
Input Format
The input consists of an integer value 'n', representing the meeting duration.
Output Format
The output is displayed in the following format:

If the entered meeting duration meets the specified criteria, the program outputs

"Meeting scheduled successfully!"


7

17

17
01

01
If the entered meeting duration is invalid, the program outputs an error message
10

0
01

01

01
indicating the issue.
00
10

10

10
1
24

24

24

24
"Error: Invalid meeting duration. Please enter a positive integer not exceeding
240 minutes (4 hours)."

Refer to the sample output for formatting specifications.


Sample Test Case
Input: 120
7

7
01

01

01

01
Output: Meeting scheduled successfully!
01

01

01

01
10

10

10

Answer 10
24

24

24

24
import [Link];

class InvalidDurationException extends Exception{


public InvalidDurationException(int duration){
super(duration);
}
}

public class Main{


7

7
01

01

01

1
10

public static void checkDuration(int n) throws InvalidDurationException{


01

01

01

if( (n<0) || (n>240) ){


10

10

10

10
24

24

24

24
throw new InvalidDurationException(n);
17

7
01

01

01
}
10

01

01

01
0

}
10

10

10

10
24

24

24

24
public static void main(String args[]){
Scanner scanner = new Scanner ([Link]);
int duration = [Link]();
try{
checkDuration(duration);
[Link]("Meeting scheduled successfully!");
}
catch(InvalidDurationException e){
[Link]("Error: Invalid meeting duration. Please enter a positive
integer not exceeding 240 minutes (4 hours).");
7

17

17
01

01
}
10

0
01

01

01
00
10

10

10
1

[Link]();
24

24

24

24
}
}

Status : Wrong Marks : 0/10


7

7
01

01

01

01
01

01

01

01
10

10

10

10
24

24

24

24
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10
24

24

24

24
17 Rajalakshmi Engineering College

7
01

01

01
10

01

01

01
0
10

10

10

10
Name: Arul Amudhan G Scan to verify results
24

24

24

24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 3
Batch: 2028
Degree: B.E - IT
7

17

17
01

01
10

0
2024_28_III_OOPS Using Java Lab
01

01

01
00
10

10

10
1
24

24

24

24
2028_REC_OOPS using Java_Week 8_Q3

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
7

7
01

01

01

01
In a user registration system, there is a requirement to implement a
01

01

01

01
10

10

10

username validation module. Users attempting to register must adhere to 10


24

24

24

24
specific criteria for their usernames to be considered valid.

Your task is to develop a program that takes user input for a desired
username and validates it according to the following rules:
The username must not contain any [Link] username must be at
least 5 characters long.
Implement a custom exception, InvalidUsernameException, to handle
cases where the entered username does not meet the specified criteria.
7

7
01

01

01

1
10

Input Format
01

01

01

0
10

10

10

10
24

24

24

24
The input consists of a string S, representing the desired username.
17

7
01

01

01
10

01

01

01
Output Format
0
10

10

10

10
24

24

24

24
If the username is valid, print "Username is valid: [S]".

If the username is invalid:

1. If the username is short, print "Invalid Username: Username must be at least 5


characters long"
2. If the username contains spaces, print "Invalid Username: Username cannot
contain spaces"
7

17

17
01

01
10

0
01

01

01
00

Refer to the sample output for formatting specifications.


10

10

10
1
24

24

24

24
Sample Test Case
Input: John
Output: Invalid Username: Username must be at least 5 characters long
Answer
import [Link];

class InvalidUsernameException extends Exception{


public InvalidUsernameException(String message){
7

7
super(message);
01

01

01

01
}
01

01

01

01
10

10

10

10
}
24

24

24

24

class UsernameValidator{

public static final int MIN_LENGTH = 5;

public static void validateUsername(String name) throws


InvalidUsernameException{
if([Link](" ")){
throw new InvalidUsernameException("Username cannot contain
spaces");
7

}
01

01

01

1
10

if([Link]()<MIN_LENGTH){
01

01

01

0
10

10

10

10

throw new InvalidUsernameException("Username must be at least " +


24

24

24

24
MIN_LENGTH + " characters long");
17

7
01

01

01
}
10

01

01

01
0

}
10

10

10

10
24

24

24

24
public static void main(String args[]){
Scanner scanner = new Scanner ([Link]);
String username = [Link]();
try{
validateUsername(username);
[Link]("Username is valid: " +username);
}
catch( InvalidUsernameException e){
[Link]("Invalid Username: " +[Link]());
}
7

17

17
01

01
finally{
10

0
01

01

01
00

[Link]();
10

10

10
1

}
24

24

24

24
}
}

Status : Correct Marks : 10/10


7

7
01

01

01

01
01

01

01

01
10

10

10

10
24

24

24

24
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10
24

24

24

24
17 Rajalakshmi Engineering College

7
01

01

01
10

01

01

01
0
10

10

10

10
Name: Arul Amudhan G Scan to verify results
24

24

24

24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 3
Batch: 2028
Degree: B.E - IT
7

17

17
01

01
10

0
2024_28_III_OOPS Using Java Lab
01

01

01
00
10

10

10
1
24

24

24

24
2028_REC_OOPS using Java_Week 8_Q4

Attempt : 1
Total Mark : 10
Marks Obtained : 2.5

Section 1 : Coding

1. Problem Statement
7

7
01

01

01

01
A local municipality is implementing an online voting system for a
01

01

01

01
10

10

10

community event and wants to ensure that only eligible voters (those aged 10
24

24

24

24
18 or older) can participate.

Your task is to develop a program that validates the age of individuals


attempting to vote online. If the user's age is below 18, the program should
throw a custom exception, InvalidAgeException, preventing them from
casting their vote. If the input is invalid, catch the appropriate
InputMismatchException and print the in-built exception message.

Input Format
7

The input consists of an integer representing the age.


01

01

01

1
10
01

01

01

0
10

10

10

10

Output Format
24

24

24

24
If the age is 18 or older, print "Eligible to vote"
17

7
01

01

01
10

01

01

01
0

If the age is below 18, print "Exception occurred: InvalidAgeException: Age is not
10

10

10

10
valid to vote"
24

24

24

24
If there is any other type of exception, print "An error occurred: " followed by the
in-built exception message.

Refer to the sample output for formatting specifications.


Sample Test Case
7

17

17
01

01
10

0
Input: 20
01

01

01
00
10

10

10
Output: Eligible to vote
1
24

24

24

24
Answer
import [Link];
import [Link];

class InvalidAgeException extends Exception{


public InvalidAgeException(String message){
super(message);
}
}
7

7
01

01

01

01
class VotingValidator{
01

01

01

01
10

10

10

10
public static void validateAge(int age) throws InvalidAgeException{
24

24

24

24
if(age < 18){
throw new InvalidAgeException ("Age is not valid to vote");
}
}

public static void main(String args[]){


Scanner scanner = new Scanner([Link]);
int age = -1;

try{
age = [Link]();
7

7
01

01

01

1
10

validateAge(age);
01

01

01

0
10

10

10

10

[Link]("Eligible to vote");
24

24

24

24
}
17

7
01

01

01
10

01

01

01
0

catch(InvalidAgeException e){
10

10

10

10
[Link]("Exception occured: InvalidAgeException: " +
24

24

24

24
[Link]());
}

catch(Exception e){
[Link]("An error occured: " +[Link]());
}

finally{
[Link]();
}
7

17

17
01

01
}
10

0
01

01

01
00

}
10

10

10
1
24

24

24

24
Status : Partially correct Marks : 2.5/10
7

7
01

01

01

01
01

01

01

01
10

10

10

10
24

24

24

24
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10
24

24

24

24
17 Rajalakshmi Engineering College

7
01

01

01
10

01

01

01
0
10

10

10

10
Name: Arul Amudhan G Scan to verify results
24

24

24

24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 3
Batch: 2028
Degree: B.E - IT
7

17

17
01

01
10

0
2024_28_III_OOPS Using Java Lab
01

01

01
00
10

10

10
1
24

24

24

24
2028_REC_OOPS using Java_Week 8_Q5

Attempt : 1
Total Mark : 10
Marks Obtained : 4.5

Section 1 : Coding

1. Problem Statement
7

7
01

01

01

01
In a file management system, users are required to provide a valid file
01

01

01

01
10

10

10

name when creating new files. The system enforces specific rules for file 10
24

24

24

24
names to maintain consistency and avoid potential issues. Your task is to
implement a Java program named FileNameValidator that takes user input
for a file name and validates it according to the specified rules.

Rules for Valid File Name:


The file name must consist of alphanumeric characters (letters and digits)
[Link] file name must have a minimum length of 3 characters.
Implement a custom exception, FileNameValidator, to handle cases where
the entered filename does not meet the specified criteria.
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10

Input Format
24

24

24

24
The input consists of a string S, representing the desired filename.
17

7
01

01

01
10

01

01

01
Output Format
0
10

10

10

10
24

24

24

24
The output is displayed in the following format:

If the entered file name meets the specified criteria, the program outputs

"Valid file name"

If the entered file name does not meet the criteria and triggers the
InvalidFileNameException, the program outputs

"Error: Invalid file name. It must be alphanumeric and have a minimum length of
3 characters."
7

17

17
01

01
10

0
01

01

01
00
10

10

10
1
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: myfile123
Output: Valid file name
Answer
import [Link];
7

7
01

01

01

01
class InvalidFileNameException extends Exception{
01

01

01

01
10

10

10

10
public InvalidFileNameException(String message){
24

24

24

24
super(message);
}
}

class FileNameValidator{

public static void validateFileName(String fname) throws


InvalidFileNameException{
7

if([Link]() < 3){


01

01

01

1
10

throw new InvalidFileNameException("Fie name is too short.");


01

01

01

0
10

10

10

10

}
24

24

24

24
17

7
01

01

01
for(char c : [Link]()){
10

01

01

01
0

if(![Link](c)){
10

10

10

10
throw new InvalidFileNameException("File name contains invalid
24

24

24

24
characters.");
}
}
}

public static void main(String args[]){


Scanner ip = new Scanner([Link]);
String fName = [Link]();

try{
7

17

17
01

01
validateFileName(fName);
10

0
01

01

01
00

[Link]("Valid file name");


10

10

10
1

}
24

24

24

24
catch(InvalidFileNameException e){
[Link]("Error: Invalid file name. It must be alphanumerical and
have a minimum length of 3 characters.");
}

finally{
[Link]();
}
}
7

7
01

01

01

01
}
01

01

01

01
10

10

10

Status : Partially correct 10


Marks : 4.5/10
24

24

24

24
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10
24

24

24

24
17 Rajalakshmi Engineering College

7
01

01

01
10

01

01

01
0
10

10

10

10
Name: Arul Amudhan G Scan to verify results
24

24

24

24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 3
Batch: 2028
Degree: B.E - IT
7

17

17
01

01
10

0
2024_28_III_OOPS Using Java Lab
01

01

01
00
10

10

10
1
24

24

24

24
REC_2028_OOPS using Java_Week 8_MCQ

Attempt : 1
Total Mark : 15
Marks Obtained : 15

Section 1 : MCQ

1. How do you create an unchecked custom exception?


7

7
01

01

01

01
Answer
01

01

01

01
10

10

10

By extending RuntimeException 10
24

24

24

24

Status : Correct Marks : 1/1

2. What will be the output of the following code?

class MyException extends Exception {


public MyException() {
super("Default Exception Message");
}
7

7
01

01

01

}
10
01

01

01

0
10

10

10

10
24

24

24

24
class Test {
17

7
01

01

01
public static void main(String[] args) {
10

01

01

01
0

try {
10

10

10

10
24

24

24

24
throw new MyException();
} catch (MyException e) {
[Link]([Link]());
}
}
}
Answer
Default Exception Message
Status : Correct Marks : 1/1
7

17

17
01

01
10

0
01

01

01
00
10

10

10
1
24

24

24

24
3. What will be the output for the following code?

import [Link].*;

class UnderageException extends Exception {


public UnderageException(String message) {
super(message);
}
}
7

7
01

01

01

01
class Test {
01

01

01

01
public static void main(String[] args) {
10

10

10

10
24

24

24

24
try {
int age = 17;
if (age < 18) {
throw new UnderageException("Underage, cannot proceed");
}
} catch (UnderageException e) {
[Link]([Link]());
}
}
}
7

7
01

01

01

1
10

Answer
01

01

01

0
10

10

10

10
24

24

24

24
Underage, cannot proceed
17

7
01

01

01
10

01

01

01
Status : Correct Marks : 1/1
0
10

10

10

10
24

24

24

24
4. What will be the output for the following code?

class NegativeBalanceException extends Exception {


public NegativeBalanceException(String message) {
super(message);
}
}

class Test {
7

17

17
01

01
10

0
public static void main(String[] args) {
01

01

01
00
10

10

10
try {
1
24

24

24

24
double balance = -500;
if (balance < 0) {
throw new NegativeBalanceException("Balance cannot be
negative");
}
} catch (NegativeBalanceException e) {
[Link]("Error: " + [Link]());
}
}
}
7

7
01

01

01

01
01

01

01

01
Answer
10

10

10

10
24

24

24

24
Error: Balance cannot be negative
Status : Correct Marks : 1/1

5. What is the purpose of a custom exception in Java?

Answer
To create user-defined exceptions for specific scenarios
Status : Correct Marks : 1/1
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10
24

24

24

24
6. What will be the output for the following code?
17

7
01

01

01
10

01

01

01
0

class InvalidUsernameException extends Exception {


10

10

10

10
24

24

24

24
public InvalidUsernameException(String message) {
super(message);
}
}

class Test {
public static void main(String[] args) {
try {
String username = "abc";
if ([Link]() < 5) {
7

17

17
01

01
throw new InvalidUsernameException("Username must be at
10

0
01

01

01
00

least 5 characters long");


10

10

10
1
24

24

24

24
}
} catch (InvalidUsernameException e) {
[Link]([Link]());
}
}
}
Answer
Username must be at least 5 characters long
Status : Correct Marks : 1/1
7

7
01

01

01

01
01

01

01

01
10

10

10

10
24

24

24

24
7. Which keyword is used to explicitly throw a custom exception?

Answer
throw
Status : Correct Marks : 1/1

8. Which of the following is true about custom exceptions?


7

Answer
01

01

01

1
10
01

01

01

Custom exceptions must extend either Exception or RuntimeException


10

10

10

10
24

24

24

24
Status : Correct Marks : 1/1
17

7
01

01

01
10

01

01

01
0
10

10

10

10
9. What will be the output for the following code?
24

24

24

24
import [Link].*;

class OutOfStockException extends Exception {


public OutOfStockException(String message) {
super(message);
}
}
7

17

17
01

01
class Test {
10

0
01

01

01
public static void main(String[] args) {
00
10

10

10
1

try {
24

24

24

24
int stock = 0;
if (stock == 0) {
throw new OutOfStockException("Item is out of stock");
}
} catch (OutOfStockException e) {
[Link]([Link]());
}
}
}
7

7
01

01

01

01
Answer
01

01

01

01
10

10

10

Item is out of stock 10


24

24

24

24

Status : Correct Marks : 1/1

10. What will be the output for the following code?

import [Link].*;

class NegativeAgeException extends Exception {


public NegativeAgeException(String message) {
7

super(message);
01

01

01

1
10
01

01

01

}
0
10

10

10

10
24

24

24

24
}
17

7
01

01

01
10

01

01

01
0

class Test {
10

10

10

10
24

24

24

24
public static void main(String[] args) {
try {
int age = -5;
if (age < 0) {
throw new NegativeAgeException("Age cannot be negative");
}
} catch (NegativeAgeException e) {
[Link]([Link]());
}
}
7

17

17
01

01
}
10

0
01

01

01
00
10

10

10
Answer
1
24

24

24

24
Age cannot be negative
Status : Correct Marks : 1/1

11. What will be the output for the following code?

class InvalidVotingAgeException extends Exception {


public InvalidVotingAgeException(String message) {
super(message);
7

7
01

01

01

01
}
01

01

01

01
}
10

10

10

10
24

24

24

24

class Test {
public static void main(String[] args) {
try {
int age = 15;
if (age < 18) {
throw new InvalidVotingAgeException("You are not eligible to
vote");
}
[Link]("Eligible to vote");
7

7
01

01

01

} catch (InvalidVotingAgeException e) {
10
01

01

01

[Link]([Link]());
10

10

10

10
24

24

24

24
}
17

7
01

01

01
}
10

01

01

01
0

}
10

10

10

10
24

24

24

24
Answer
You are not eligible to vote
Status : Correct Marks : 1/1

12. What will be the output for the following code?

import [Link].*;
7

17

17
01

01
class TemperatureTooHighException extends Exception {
10

0
01

01

01
00

public TemperatureTooHighException(String message) {


10

10

10
1
24

24

24

24
super(message);
}
}

class Test {
public static void main(String[] args) {
try {
int temperature = 110;
if (temperature > 100) {
throw new TemperatureTooHighException("Temperature too
7

7
01

01

01

01
high");
01

01

01

01
}
10

10

10

10
24

24

24

24
} catch (TemperatureTooHighException e) {
[Link]([Link]());
}
}
}
Answer
Temperature too high
Status : Correct Marks : 1/1
7

7
01

01

01

1
10
01

01

01

13. what is the output of the following code?


10

10

10

10
24

24

24

24
17

7
class MyException extends Exception {

01

01

01
10

01

01

01
public MyException(String message) {
0
10

10

10

10
super(message);
24

24

24

24
}
}

class Test {
public static void main(String[] args) {
try {
throw new MyException("Error occurred");
} catch (MyException e) {
[Link](e);
7

17

17
}
01

01
10

0
01

01

01
}
00
10

10

10
}
1
24

24

24

24
Answer
MyException: Error occurred
Status : Correct Marks : 1/1

14. What will happen if a checked custom exception is thrown inside a


method without being caught or declared?
7

7
Answer
01

01

01

01
01

01

01

01
Compilation Error
10

10

10

10
24

24

24

24
Status : Correct Marks : 1/1

15. what is the output of the following code?

class MyException extends Exception {


public MyException(String message) {
super(message);
}
}
7

7
01

01

01

1
10
01

01

01

class Test {
10

10

10

10
24

24

24

24
static void check() throws MyException {
17

7
01

01

01
throw new MyException("Custom Exception Occurred");
10

01

01

01
0

}
10

10

10

10
24

24

24

24
public static void main(String[] args) {
try {
check();
} catch (Exception e) {
[Link]([Link]());
}
}
}
7

17

17
Answer
01

01
10

0
01

01

01
00

Custom Exception Occurred


10

10

10
1
24

24

24

24
Status : Correct Marks : 1/1
7

7
01

01

01

01
01

01

01

01
10

10

10

10
24

24

24

24
7

7
01

01

01

1
10
01

01

01

0
10

10

10

10
24

24

24

24

You might also like