| Author |
preparing for SCJP 5
|
partho mukherjee
Greenhorn
Joined: Jun 08, 2006
Posts: 13
|
|
Hi pals, just set the ball rolling for SCJP 5... I know a lot among you out there have done the same long time back... anybody want to study in group? my mail id is partho.protim@gmail.com.. we can discuss problems and confusions.. afterall, united we stand(against the examiners trying their best to find out the little that we don't know, and not the lot that we do!) so do mail me.. and post replies..
|
 |
Raghavan Muthu
Ranch Hand
Joined: Apr 20, 2006
Posts: 3327
|
|
Good luck partho.
|
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
|
 |
anuj bhatnagar
Greenhorn
Joined: Aug 06, 2007
Posts: 27
|
|
Originally posted by partho mukherjee: Hi pals, just set the ball rolling for SCJP 5... I know a lot among you out there have done the same long time back... anybody want to study in group? my mail id is partho.protim@gmail.com.. we can discuss problems and confusions.. afterall, united we stand(against the examiners trying their best to find out the little that we don't know, and not the lot that we do!) so do mail me.. and post replies..
|
thanks & regards,<br />Anuj Bhatnagar
|
 |
partho mukherjee
Greenhorn
Joined: Jun 08, 2006
Posts: 13
|
|
see the code snippet below public class Horse extends Animal { private Halter myHalter; public void tie(LeadRope rope) { myHalter.tie(rope); // Delegate tie behavior to the // Halter object } } public class Halter { public void tie(LeadRope aRope) { // Do the actual tie work here } } this code confuses me as the Halter object has never been instantiated and so it quite evidently gives null pointer exception when I invove the method tie() of Horse class. Am I missing out on something? This I have taken from K & B chapter 2.
|
 |
Dave Walsh
Greenhorn
Joined: Jun 21, 2007
Posts: 24
|
|
Originally posted by partho mukherjee: see the code snippet below public class Horse extends Animal { private Halter myHalter; public void tie(LeadRope rope) { myHalter.tie(rope); // Delegate tie behavior to the // Halter object } } public class Halter { public void tie(LeadRope aRope) { // Do the actual tie work here } } this code confuses me as the Halter object has never been instantiated and so it quite evidently gives null pointer exception when I invove the method tie() of Horse class. Am I missing out on something? This I have taken from K & B chapter 2.
You just answered your own question: instantiate it somewhere ! private Halter myHalter = new Halter();
|
 |
partho mukherjee
Greenhorn
Joined: Jun 08, 2006
Posts: 13
|
|
i have a problem in understanding KB chapter 2 at a point.. see the code below.. public class Animal { public void eat() { System.out.println("Generic Animal Eating Generically"); } } public class Horse extends Animal { public void eat() { System.out.println("Horse eating hay "); } public void eat(String s) { System.out.println("Horse eating " + s); } }
|
 |
partho mukherjee
Greenhorn
Joined: Jun 08, 2006
Posts: 13
|
|
sorry I missed the question in the above post.. when we run the following code what should be the output? Animal animal = new Horse(); animal.eat(); my guess was Generic animal eating Generically but KB says Horse eating hay is that a special case?
|
 |
Mohammad Hossain
Greenhorn
Joined: Jul 26, 2007
Posts: 14
|
|
Animal is the superclass of Horse. So, Horse is also a kind of Animal. Because of that it is possible to assign Horse object to Animal. Here we are creating an Animal reference by "Animal animal", but when we say new Horse() we are creating a "Horse object". So the variable animal is a reference to a Horse object. Animal is actually a Horse. that's why its calling Horse's eat() method.
|
Live Free Or Die
|
 |
Rahul K Sharma
Greenhorn
Joined: Aug 13, 2007
Posts: 3
|
|
guys, I am also plannning to appear for jcp1.5 in mid of coming september. I wana solve as many problem as I can. so pals please feel free to post intricated problems or if you find something really interesting about 1.5 then dont forget to share with others. thanks
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
|
Rahul, please check your private messages - you can see them by clicking "My Profile" at the top right of the page.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: preparing for SCJP 5
|
|
|