• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

preparing for SCJP 5

 
partho mukherjee
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good luck partho.
 
anuj bhatnagar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
partho mukherjee
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rahul K Sharma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul, please check your private messages - you can see them by clicking "My Profile" at the top right of the page.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic