File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Associate Certification (SCJA,OCAJ 5/6) and the fly likes SCJA Question About Ancestor and Sub Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Associate Certification (SCJA,OCAJ 5/6)
Reply Bookmark "SCJA Question About Ancestor and Sub Classes" Watch "SCJA Question About Ancestor and Sub Classes" New topic
Author

SCJA Question About Ancestor and Sub Classes

Oscar Hansen
Greenhorn

Joined: Jul 09, 2008
Posts: 10
I am reading SCJA book by Cameron McKenzie and on page 166, I did not understand the answer to a question. Can someone explain me:

Sub classes:
- Should not be used as a method parameters when an ancestor class will suffice.

Thanks in advance!
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4967

The basic idea is that you always want to use the most general component whenever possible.

So, if I have a method, and all it does is print out the toString() method, I shouldn't force the argument to be a String, when I could just make the argument an Object. After all, every instance of an Object has a toString() method.

The more general, or abstract an argument is, the more flexible the method becomes. It makes your code more flexible and pluggable. That's the general idea.


Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: SCJA Question About Ancestor and Sub Classes
 
Similar Threads
please comment
SCJA certification
WA #2 ..... word association
Help me with this question from mock exam
An ancestor/descendant question??