I have a problem where I have some class say
public class Foo {
public Foo() {
// Do stuff
}
public void generalMethod() {
//to general stuff
}
}
public class Bar extends Foo {
public Bar() {
//do stuff
}
public void uniqueMethod() {
//do stuff
}
}
public class Driver() {
public static void main(String[] args) {
Foo test = new Bar();
test.uniqueMethod(); //this causes an error
}
}
So i get an error which says, that the method uniqueMethod()
is undefined for Foo, but when I change the assignment to Bar test = new Bar();
the problem goes away. I dont understand as it should work with Foo test = new Bar();
Can someone suggest a reason for which why this error occurs?
Thank you in advance.