Thursday, August 4, 2011

Assignment 9 Exercises for chapter 11, 12, 13

/**********************************************
*T'Nora Green
*Assignment 9, Chapter 11,  Exercise 11
***********************************************/

i= 5, factorial = 1


/**********************************************
*T'Nora Green
*Assignment 9, Chapter 11,  Exercise 12
***********************************************/

for(;!entry = q;)
{
System.out.println("Enter 'q' to quit: ");
entry = stdIn.nextLine();
}



/*********************************************
*T'Nora Green
*Assignment 9, Chapter 12,  Exercise 8
**********************************************/

a)     doIt(); calls the subclass's doIt method again, instead of calling the superclass's doIt; method,\ that creates an infinite loop that causes only a blank screen to show.


b) change doIt()to super.doIt()


/***********************************************
*T'Nora Green
*Assignment 9, Chapter 12,  Exercise 12
************************************************/

structural member \beam: inheritance
building \floor: composition
company \fixed assets: composition
employee\ salesperson:  inheritance
forest \tree: composition
bird\robin:  inheritance
class \method:  composition
neurosis\ paranoia:  inheritance



/*********************************************
*T'Nora Green
*Assignment 9, Chapter 13,  Exercise 3
**********************************************/

output:
sparky = bark, bark     lassie = Animal@4fe5e2c3
Press any key to continue . . .


how the output is generated:
The variable sparky was instantiated as a Dog, and Lassie was instantiated as an animal. When the JVM sees sparky inside the println statement, the JVM calls Dog's toString method. When the JVM sees Lassie inside the println statement, the JVM calls Object's toString method.

/*********************************************
*T'Nora Green
*Assignment 9, Chapter 13,  Exercise 8
**********************************************/

Dog lassie = (Dog) animals[0];
Cat fluffy = (Cat) animals[1];

No comments:

Post a Comment