Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. derived class function is not accessible from base class object of type derived

derived class function is not accessible from base class object of type derived

Scheduled Pinned Locked Moved C#
help
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kumarprabhakar74
    wrote on last edited by
    #1

    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

    M R 2 Replies Last reply
    0
    • K kumarprabhakar74

      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

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Well, thats true! Cause function2 is not a method of test. What have you expected? All the best, Martin

      K 7 Replies Last reply
      0
      • K kumarprabhakar74

        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

        R Offline
        R Offline
        Russell Jones
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • M Martin 0

          Well, thats true! Cause function2 is not a method of test. What have you expected? All the best, Martin

          K Offline
          K Offline
          kumarprabhakar74
          wrote on last edited by
          #4

          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

          C 1 Reply Last reply
          0
          • M Martin 0

            Well, thats true! Cause function2 is not a method of test. What have you expected? All the best, Martin

            K Offline
            K Offline
            kumarprabhakar74
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • M Martin 0

              Well, thats true! Cause function2 is not a method of test. What have you expected? All the best, Martin

              K Offline
              K Offline
              kumarprabhakar74
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • M Martin 0

                Well, thats true! Cause function2 is not a method of test. What have you expected? All the best, Martin

                K Offline
                K Offline
                kumarprabhakar74
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • M Martin 0

                  Well, thats true! Cause function2 is not a method of test. What have you expected? All the best, Martin

                  K Offline
                  K Offline
                  kumarprabhakar74
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • M Martin 0

                    Well, thats true! Cause function2 is not a method of test. What have you expected? All the best, Martin

                    K Offline
                    K Offline
                    kumarprabhakar74
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    • M Martin 0

                      Well, thats true! Cause function2 is not a method of test. What have you expected? All the best, Martin

                      K Offline
                      K Offline
                      kumarprabhakar74
                      wrote on last edited by
                      #10

                      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

                      C 1 Reply Last reply
                      0
                      • K kumarprabhakar74

                        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

                        C Offline
                        C Offline
                        Colin Angus Mackay
                        wrote on last edited by
                        #11

                        Then reference it as a type test1. Type test does not have a function2() method, therefore, if you have a reference of type test, even althought the actual object is of type test1, you cannot access function2().


                        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

                        1 Reply Last reply
                        0
                        • K kumarprabhakar74

                          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

                          C Offline
                          C Offline
                          Colin Angus Mackay
                          wrote on last edited by
                          #12

                          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

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups