Jump to content

  • Log In with Google      Sign In   
  • Create Account


Java Inheritance Resources?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 mrchrismnh   Members   -  Reputation: 82

Like
0Likes
Like

Posted 04 August 2011 - 11:36 AM

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


Sponsor:

#2 mrchrismnh   Members   -  Reputation: 82

Like
0Likes
Like

Posted 04 August 2011 - 11:59 AM

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


#3 Antheus   Members   -  Reputation: 2385

Like
0Likes
Like

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 sjaakiejj   Members   -  Reputation: 130

Like
1Likes
Like

Posted 05 August 2011 - 10:46 AM

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

#5 alnite   Crossbones+   -  Reputation: 1990

Like
0Likes
Like

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS