Skip to main content
GameDev.net gamedev.net
🔒 Locked

Java Inheritance Resources?

Started by mrchrismnh Aug 4, 2011 at 5:36 PM 3 replies 1.9k views
Original Post
mrchrismnh
mrchrismnh
What I am looking for: nitty-gritty rules of Java inheritance, specifically how the superclasses of constructors work and why it is that my composited class members don't seem to be allowed to be used in extended classes. I am looking for online resources, I can find the problem out myself.

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;
}
"It's like naming him Asskicker Monstertrucktits O'Ninja" -Khaiy

mrchrismnh
mrchrismnh
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.
"It's like naming him Asskicker Monstertrucktits O'Ninja" -Khaiy

Antheus
Antheus

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.
[/quote]

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
sjaakiejj
sjaakiejj
In regards to Resources on Java, one of my old lecturers wrote a book about Java, going over every important topic in the language, making extensive use of Inheritance and Generics in the later chapters. It's the book that he also uses for his lectures, and it makes an excellent resource for the language.

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".
alnite
alnite

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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.