derived class function is not accessible from base class object of type derived
-
public class test { public void function1() { } } public class test1 : test { public void function2() { } } test t; test1 t1 = new test1(); t = t1; t.function1(); t.function2(); //Show error
abc
kumarprabhakar74 wrote:
test t; test1 t1 = new test1(); t = t1; t.function1(); t1.function2()//No Error t.function2(); //Show error
you can only call function2 on a test1 object or a subclass of test1. The fact that t happens to contain a test1 object doesn't matter as the compiler cannot know what kind of object will be referenced by t apart from the fact that it is of type test. HTH Russ
-
Well, thats true! Cause function2 is not a method of test. What have you expected? All the best, Martin
Thanks for reply. We have created object at run time on the basis of derived class that's why we had used base class object but we had faced his dificulty. All the abstract methods of base class which is override in derived class is visible but public functions of derived class are not visible. Can you help us to make these functions are visible. Thanks, Kumar Prabhakar
abc
-
Well, thats true! Cause function2 is not a method of test. What have you expected? All the best, Martin
Thanks for reply. We have created object at run time on the basis of derived class that's why we had used base class object but we had faced his dificulty. All the abstract methods of base class which is override in derived class is visible but public functions of derived class are not visible. Can you help us to make these functions are visible. Thanks, Kumar Prabhakar
abc
-
Well, thats true! Cause function2 is not a method of test. What have you expected? All the best, Martin
Thanks for reply. We have created object at run time on the basis of derived class that's why we had used base class object but we had faced his dificulty. All the abstract methods of base class which is override in derived class is visible but public functions of derived class are not visible. Can you help us to make these functions are visible. Thanks, Kumar Prabhakar
abc
-
Well, thats true! Cause function2 is not a method of test. What have you expected? All the best, Martin
Thanks for reply. We have created object at run time on the basis of derived class that's why we had used base class object but we had faced his dificulty. All the abstract methods of base class which is override in derived class is visible but public functions of derived class are not visible. Can you help us to make these functions are visible. Thanks, Kumar Prabhakar
-
Well, thats true! Cause function2 is not a method of test. What have you expected? All the best, Martin
Thanks for reply. We have created object at run time on the basis of derived class that's why we had used base class object but we had faced his dificulty. All the abstract methods of base class which is override in derived class is visible but public functions of derived class are not visible. Can you help us to make these functions are visible.
abc
-
Well, thats true! Cause function2 is not a method of test. What have you expected? All the best, Martin
Thanks for reply. We have created object at run time on the basis of derived class that's why we had used base class object but we had faced his dificulty. All the abstract methods of base class which is override in derived class is visible but public functions of derived class are not visible.
abc
-
Well, thats true! Cause function2 is not a method of test. What have you expected? All the best, Martin
We have created object at run time on the basis of derived class that's why we had used base class object but we had faced his dificulty. All the abstract methods of base class which is override in derived class is visible but public functions of derived class are not visible.
abc
-
Thanks for reply. We have created object at run time on the basis of derived class that's why we had used base class object but we had faced his dificulty. All the abstract methods of base class which is override in derived class is visible but public functions of derived class are not visible. Can you help us to make these functions are visible. Thanks, Kumar Prabhakar
abc
Then reference it as a type
test1
. Typetest
does not have afunction2()
method, therefore, if you have a reference of typetest
, even althought the actual object is of typetest1
, you cannot accessfunction2()
.
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... * Reading: Developer Day 5 Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
-
We have created object at run time on the basis of derived class that's why we had used base class object but we had faced his dificulty. All the abstract methods of base class which is override in derived class is visible but public functions of derived class are not visible.
abc
Seriously - How many times do you think you need to repeat the same question!?
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... * Reading: Developer Day 5 Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website