• 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

preparing for SCJP 5

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good luck partho.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic