Java OOP Assessment - Rectangle Program
Based on the given Rectangle program, answer the following questions.
Question 1 (Conceptual)
Identify the class and object in the program. Explain how this program demonstrates the
concept of Object-Oriented Programming (OOP).
Question 2 (Method & Return Type)
Explain the purpose of the methods setw(int x), seth(int x), and area(). What will happen if
the return type of area() is changed from int to void?
Question 3 (Find the Output)
If the input given is:
5
10
What will be the output? Justify your answer.
Question 4 (Access Modifier)
If the variables w and h are changed to private, will the program still work? Explain your
reasoning.
Question 5 (Exception Handling - MCQ)
If the user inputs:
5
abc
What will happen?
A) Compilation Error
B) Runtime Error - NumberFormatException
C) Runtime Error - InputMismatchException
D) Output will be 0
Choose the correct answer and justify.