0% found this document useful (0 votes)
3 views1 page

Answers Lab 4

The document contains answers to exercises related to class design and method behavior in object-oriented programming. It discusses concepts such as static variables, method overriding and overloading, legality of assignments between different account types, and runtime errors. Additionally, it addresses compiler errors related to method invocations and the use of inheritance in method calls.

Uploaded by

Arsham Moayedi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Answers Lab 4

The document contains answers to exercises related to class design and method behavior in object-oriented programming. It discusses concepts such as static variables, method overriding and overloading, legality of assignments between different account types, and runtime errors. Additionally, it addresses compiler errors related to method invocations and the use of inheritance in method calls.

Uploaded by

Arsham Moayedi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Answers for Lab 2

-----------------------------------------------

EXERCISE 1

1. Should instance variable interestRate be declared as static? Explain.

2. Write the output from the test harness for class SavingsAccount.

EXERCISE 2

3. Which method(s) of the class CheckingAccount demonstrate overriding? Which


methods demonstrate overloading?

4. Is bacc0 = chacc1 legal? Why?

5. Is chacc1 = bacc1 legal? Why?

6. On which variables bacc1, chacc1, sacc1 was the invocation to method


deductFees() valid? Explain.

7. Which compilation error(s) could be fixed through casting? Which one(s)


could not be fixed? Why?

8. Why did the program crash? What kind of exception was thrown?

9. What was the runtime error obtained when changing super.deposit(amount)


to deposit(amount) in class CheckingAccount.java?

EXERCISE 3

10. Why does the compiler issue an error message when invoking
newAcc.getTransactionCount()? Why does the compiler issue an error message when
invoking newAcc.getInterestRate()?

11. Can you tell whether in the statement String accountInfo = newAcc.toString();
the
method toString() being invoked is from the class CheckingAccount or from the class
SavingsAccount? Explain your answer.

You might also like