Lecture73 - Question 1 Determine whether each of the following statements is true or false If the statement is true circle the\"T if false circle the\"F(1

# Lecture73 - Question 1 Determine whether each of the...

• Notes
• Pakistani
• 23

This preview shows page 1 - 8 out of 23 pages.

Question 1. Determine whether each of the following statements is true or false. If the statement is true, circle the "T"; if false circle the "F". (1 mark) T / F Abstract classes that have no abstract methods can be instantiated. (1 mark) T / F For immutable objects, equals and = = are equivalent. Object and therefore inherits all of its methods (including equals). (1 mark) T / F A stack can contain only an object reference, not an actual object 1
Question 2: A system has modules P, Q, R and S with the following characteristics: • P uses R; • R uses S; • Q uses R; • S uses P; (1 mark) (a) Draw a diagram showing which modules use each other (i.e. draw a “uses” diagram). Answer: P R S Q 2
(1 mark) (b) Convert the diagram from a “uses” diagram to a “depends diagram” (according to the MIT course notes) S PS S RS S PR S QR Q S R P 3
(1 mark) (c) If the implementation of a method in R changes, but all specifications in the system remain the same, which other modules might need to be updated? the system remain the same, which other modules might need to be updated? 4
Question 3: class Account { double balance; /** @ constructs a new Account with balance = initialBalance */ Account( double initialBalance) { this .balance = initialBalance; } void balanceIncrease(double increase) { this.balance=this.balance + increase; } /** Returns a textual description of the type of this account. */ String getAccountType() { return "Account"; } /** @ prints to standard output the type of this account followed by the balance. */ void printBalance() { System.out.println( this .getAccountType() + ": \$" + balance); 5
}} class OverdraftAccount extends Account { double creditLimit; /** @ constructs a new OverdraftAccount with balance = initialBalance, * creditLimit = initialCreditLimit */ OverdraftAccount( double initialBalance, double initialCreditLimit) { super (initialBalance); this .creditLimit = initialCreditLimit; } /** Returns a textual description of the type of this account. * @return the String "OverdraftAccount" */ String getAccountType() { return "OverdraftAccount"; } } (2 marks) ( a ) Identify the Account and overdraftAccount classes as mutable or immutable. /** Account represents a mutable bank account. **/ /** OverdraftAccount represents a mutable bank account with a credit limit.*/ 6