I have 2 classes as follows.
public absract class myAbstracClass{
//various methods and stuff.
}
public class myImplmentationOfAbstractClass extends myAbstractClass {
//just implments a call to the abstract class in the constructor.
//no extrac functionality is added in this instance.
}
In a third class I have a method
public class someFunctionality{//
//default constructor
public static void myMethod(myAbstractClass abc)
//do stuff with abc
}
In my code I then call this method
public class doWork{
public static void main(){
//create my implmented class
myImplmentationOfAbstractClass myABC = new myImplmentationOfAbstractClass();
//send this class to my function
someFunctionality.myMethod(myABC);//this causes an NPE
}
}
I’m obviously missing something, and I’m not finding it on google.
For now I’ve changed my method to accept a myImplementationOfAbstractClass object. But this seems bad new as I expect to need to use the abstract class again, and extnd it for specific instances.
Am I going about this incorrectly, or can I not send a subclass of a superclass to a method expecting a copy of the superclass?
thanks in advance.
David.
edit:
I just want to say thanks to everyone who has taken the time to answer. You are all correct. The problem was elsewhere.
It turns out that within my function I was declaring another ‘temp object’ and I was declaring its members in a bad order… took a while to find that one!
Once again, thanks guys, The process of writing the question was as helpfull as the responses. We all got to the same conclusion, at about the sime time (me I realised it just as you where posting the response I guess).
Error in your method
myMethod.this code
cannt’ throw NPE