• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

overriding classes - tutorial

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody give a good URL to overriding/inheriting tutorial? I'm not looking for basis, I need full explanation for questions like: "Which method from which class will be invoked?", regarding from:
- overriden/overriding methods' modifiers;
- methods' invocation place (for example, a call from another method belonging to the same/ inheriting class);
- object's run-time and compile-time class.
Thanx in advance.

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

Forget about dreaming, live in java.
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see chapter 12 of my book.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.amazon.com/exec/obidos/tg/detail/-/0072226846/qid=1090771981/sr=8-1/ref=sr_8_xs_ap_i1_xgl14/103-6096931-2855803?v=glance&s=books&n=507846

:-) Seriously, this book will teach you everything you need.

In a nutshell, here are the rules for overriding:

The overriding method:
- cannot have a more restrictive access modifier than the parent
- argument list must match exactly
- return type must match exactly
- access level can be less restritive
- ex. parent method is protected, child can be public
- cannot throw new or broader checked exceptions
- can throw narrower or fewer checked exceptions
- ex. parent throws IOException, child can throw FileNotFoundException or nothing but can't throw Exception
- cannot override a method marked final
- cannot override a method that can't be inherited due to access restriction
- ex. private method cannot ever be overriden

Also, the method invoked is determined at run-time based on the actual object on the heap, regardless of reference variable type.

Brian

P.S. Wish me luck, I'm taking the test on Wednesday!
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't read Kathy's book, but I did participate in the technical review of the exams contained at the end of each chapter. After the technical review of K&B, I removed a lot of questions from my mock exam that were either too difficult or too far beyond the scope of the real exam. What is left are questions that are only a little more difficult than those on the real exam. The score that a person gets on the real exam is typically higher than their score on my exam.

My book is completely different from K&B. A person that has never read a Java fundamentals textbook could pick up the K&B SCJP study guide and have no trouble understanding it. My book is organized differently. The chapters in my book are intended to provide only a short preview of the material on the exam contained in the chapter. The detailed explanations of the topics are provided as explanations for questions. The organization of my book allows the reader to easily avoid reading material that the reader does not need.

The organization of my book allows it to work very well as a workbook to accompany any other study guide such as K&B. While a typical study guide has long chapters and short exams, my book has very short chapters but very long exams with detailed answer explanations.

My book can also be used by those that have already read a Java fundamentals textbook and are not interested in rereading the same material in a study guide. Instead, an experience Java programmer might prefer to jump right into a mock exam that will allow the person to identify the topics that they need to review, and the review of those topic is provided by the detailed answer explanations that follow the exam. You could say that my book is like a study guide turned inside out.

I receive a lot of email from people that prepared for the exam by using nothing more than my exams and the detailed answer explanations. Of course, I also receive a lot of email from people that used my exams and detailed answer explanations as a workbook along with a study guide such as K&B.

Michal, I hope your still here, because I want to give you another URL. Please see Section 8.4.6 of the Java Language Specification. The JLS will tell you everything that you ever wanted to know about inheritance. K&B was not published until after I completed the exam, so the JLS was one of my primary sources of exam preparation material. Of course, the JLS does not contain mock exams, so I created my own. Those exams have been available on-line for a couple years. Now they are available in my book along with some additional material that is not available on my web site. If you would like to buy a book that contains material that has been reviewed by the entire world for about two years, then my book is for you!
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic