Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

polymorphism

 
sandeep Talari
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chapeter 2 ..94th page
in kathy book scjp..

how does this following code works any body please explain

public class Horse extends Animal
{
private Halter myHalter;
public void tie(LeadRope rope)
{
myHalter.tie(rope);
}
}
public class Halter(
public void tie (LeadRope aRope)
{}

}
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use the code tags,

looks like you're missing a LeadRope class,

have you run it through a compiler?

what was the error?
 
sandeep Talari
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks paul
sorry this is the exact code given in the kathy sierra book of scjp
i didn't get it nothing is there

i remember the exception its nullpointer exception
 
Mark Newton
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sandeep, I think you need to read HowToAskQuestionsOnJavaRanch.

To get meaningful advice, you really need to post a lot more information than you've given us, for example, you're obviously running this code somehow, but I don't see a main method anywhere. I haven't tried, but I'm pretty sure that the code you've given us won't compile, so something is definitely missing between what you're seeing and what you're telling us that you're seeing.

Also, just saying that you remember it was a NullPointerException isn't really enough - you should have a stack trace that tells you exactly where the exception was thrown, among other things - all of that is useful information.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12086
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also, be sure you read the book carefully. There are many examples in the book that are not meant to be complete, executable code samples, but just enough code to illustrate a point. It is not all meant to be typed up, compiled and run.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic