Java Inheritance Resources?
#1 Members - Reputation: 82
Posted 04 August 2011 - 11:36 AM
What I am not looking for: another tutorial explaining how to make my black labrador named steve say "woof woof I am Steve, a subclass of dog".
My basic issue:
public class a
{
public a(;)
protected otherclass homevec;
protected otherclass startpos;
}
public class b extends a
{
public b(super();)
public b(float x, float y, float z, float w);
{
super();
//the problem: trying to do ANYTHING with any otherclass instance gets me a java NullPointerException at runtime, for example:
awaypos._x = x;
awaypos._y = y;
}
protected otherclass awaypos;
}
#2 Members - Reputation: 82
Posted 04 August 2011 - 11:59 AM
#3 Members - Reputation: 2369
Posted 04 August 2011 - 05:09 PM
Because Java is not c++ and "otherclass class;" does not call the blank constructor.
Not quite. In this regard Java is exactly like C++ and even better:
// C++ Foo * foo; // Java Foo foo;In C++ the statement is undefined and likely to crash.
The C++ equivalent of what every declaration of object does is:
Foo * foo = NULL;
Leaving this up in case it helps anyone else; it is amazing how many times the act of posting a question in a public forum led me to find a solution on my own.
Every book on Java says: "All objects are assigned to null. New instances must be created using new operator."
What Java really does not have are value objects. So something like:
// C++ Foo foo;cannot be done in Java
#4 Members - Reputation: 130
Posted 05 August 2011 - 10:46 AM
http://www.amazon.com/Java-Just-Time-John-Latham/dp/1848900252/ref=sr_1_1?ie=UTF8&qid=1312562473&sr=8-1
It's easy to read, down-to-earth, and dives much deeper into inheritance than "I'm a dog called steve".
#5 Members - Reputation: 1461
Posted 05 August 2011 - 06:32 PM
Because Java is not c++ and "otherclass class;" does not call the blank constructor. Leaving this up in case it helps anyone else; it is amazing how many times the act of posting a question in a public forum led me to find a solution on my own.
LOL. Numerous times I found the answer while typing my post.






