P
Phi!
Hello everyone,
any help with this would be appreciated as I have spent the past
afternoon trying to sort it out. I have two questions based on the
followiung information.
I have two classes: -
Class A {
Method 1() {}
}
Class B: A {
Method 1(){}
Method 2() {}
Method 3() {}
}
From another part of my program I try and call the class as follows: -
A a = new B();
I can now access method 1 from a , however I cannot access method 2 or
3 from A and I can't see why I cannot access them.
My underdtanding of inhertiance, polymorphism and OO design was that I
could do this. Question 1: what am I doing wrong here to make this
work.
Question 2: My actual program consists of 3 dervied classes and
according to an variable I must instantiate one of the three classes
but I wanted teh object to have the same name because subsequent code
in the program. I was going to do it the above way but if there is
something wrong with my thinking what would be the best way of doing
this.
Again any help would be greatfully appreciated.
Kind Regards
Phil
any help with this would be appreciated as I have spent the past
afternoon trying to sort it out. I have two questions based on the
followiung information.
I have two classes: -
Class A {
Method 1() {}
}
Class B: A {
Method 1(){}
Method 2() {}
Method 3() {}
}
From another part of my program I try and call the class as follows: -
A a = new B();
I can now access method 1 from a , however I cannot access method 2 or
3 from A and I can't see why I cannot access them.
My underdtanding of inhertiance, polymorphism and OO design was that I
could do this. Question 1: what am I doing wrong here to make this
work.
Question 2: My actual program consists of 3 dervied classes and
according to an variable I must instantiate one of the three classes
but I wanted teh object to have the same name because subsequent code
in the program. I was going to do it the above way but if there is
something wrong with my thinking what would be the best way of doing
this.
Again any help would be greatfully appreciated.
Kind Regards
Phil