My understanding is that every class in Java is a child of the Object superclass. Why, therefore, is it my compiler giving me errors for the following code:
public class ClassA {
public ClassA(){}
public String exampleMethod(String str){
//manipulate string
return str;
}
}
public class ClassB {
public ClassB(){}
public String exampleMethod(String str){
//manipulate string
return str;
}
}
public class Manager {
public Manager(){
execute(new ClassA());
execute(new ClassB());
}
public void execute(Object o){
o.exampleMethod("test");
}
}
If ClassA is a child of Object, why can I not call methods from the 'o' variable? I'm aware that I could just put ClassA & ClassB under a superclass, but I want to know why this fails.