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. Difference between in intializing the Object of the class

Difference between in intializing the Object of the class

Scheduled Pinned Locked Moved C#
14 Posts 7 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.
  • J J4amieC

    The 2nd method you're not instantiating class A, you're instantiating class B :confused:

    N Offline
    N Offline
    NET India
    wrote on last edited by
    #5

    And in Ist Method

    1 Reply Last reply
    0
    • N NET India

      class A { public virtual void get() { Console.WriteLine("Hello"); } } class B:A { public override void get() { Console.WriteLine("Fine"); } } Ist Method A e = new B(); e.get(); IInd Method B e = new B(); e.get(); Difference between in Ist Method and IInd Method of intializing the object of the the Class A

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #6

      You'll get the same output in both cases because, even though you are using class A in the 1st method, you are instantiating an instance of class B (because B inherits from A). What you can't do here, is access methods of B that aren't in A.

      Deja View - the feeling that you've seen this post before.

      My blog | My articles

      1 Reply Last reply
      0
      • S Shpendh

        Difference between in Ist Method and IInd Method Ist Method returns. "Hello" IIst Method returns. "Fine"

        spaps

        L Offline
        L Offline
        lisan_al_ghaib
        wrote on last edited by
        #7

        Nope !!!! The same output = "Fine"

        S 1 Reply Last reply
        0
        • L lisan_al_ghaib

          Nope !!!! The same output = "Fine"

          S Offline
          S Offline
          Shpendh
          wrote on last edited by
          #8

          if you do like this: A e = new A(); e.get(); B c = new B(); c.get(); you will have Hello and Fine too..

          spaps

          L 1 Reply Last reply
          0
          • S Shpendh

            if you do like this: A e = new A(); e.get(); B c = new B(); c.get(); you will have Hello and Fine too..

            spaps

            L Offline
            L Offline
            lisan_al_ghaib
            wrote on last edited by
            #9

            yes it's correct but if we have A e = new B(); //Upcasting e.get(); we will have "Fine"

            S 1 Reply Last reply
            0
            • L lisan_al_ghaib

              yes it's correct but if we have A e = new B(); //Upcasting e.get(); we will have "Fine"

              S Offline
              S Offline
              Shpendh
              wrote on last edited by
              #10

              lisan_al_ghaib wrote:

              A e = new B()

              sorry...that's my fault

              spaps

              1 Reply Last reply
              0
              • N NET India

                class A { public virtual void get() { Console.WriteLine("Hello"); } } class B:A { public override void get() { Console.WriteLine("Fine"); } } Ist Method A e = new B(); e.get(); IInd Method B e = new B(); e.get(); Difference between in Ist Method and IInd Method of intializing the object of the the Class A

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #11

                .NET- India wrote:

                Ist Method A e = new B(); e.get(); IInd Method B e = new B(); e.get(); Difference between in Ist Method and IInd Method of intializing the object of the the Class A

                The question can not be answered, as it's incorrect. Neither of the two methods creates an instance of the A class.

                Despite everything, the person most likely to be fooling you next is yourself.

                1 Reply Last reply
                0
                • N NET India

                  class A { public virtual void get() { Console.WriteLine("Hello"); } } class B:A { public override void get() { Console.WriteLine("Fine"); } } Ist Method A e = new B(); e.get(); IInd Method B e = new B(); e.get(); Difference between in Ist Method and IInd Method of intializing the object of the the Class A

                  L Offline
                  L Offline
                  leckey 0
                  wrote on last edited by
                  #12

                  This idiot cannot figure out how to use Google to answer his homework questions and likes to ask the same question again.

                  Blog link to be reinstated at a later date.

                  N 1 Reply Last reply
                  0
                  • L leckey 0

                    This idiot cannot figure out how to use Google to answer his homework questions and likes to ask the same question again.

                    Blog link to be reinstated at a later date.

                    N Offline
                    N Offline
                    NET India
                    wrote on last edited by
                    #13

                    This idiot knws very well how to use google at it's best. But i think u've a lot of free time to waste writing such a stupid or worthless answer ??????????????????????????????. If you think this is very easy question why dont u explain the solution to the probs i'm facing and for kind very information i got a solution myself. But u r the genios or the champ of champions so explain the main diff ?????????????????????????? waiting for ur reply

                    L 1 Reply Last reply
                    0
                    • N NET India

                      This idiot knws very well how to use google at it's best. But i think u've a lot of free time to waste writing such a stupid or worthless answer ??????????????????????????????. If you think this is very easy question why dont u explain the solution to the probs i'm facing and for kind very information i got a solution myself. But u r the genios or the champ of champions so explain the main diff ?????????????????????????? waiting for ur reply

                      L Offline
                      L Offline
                      leckey 0
                      wrote on last edited by
                      #14

                      *yawn*

                      Blog link to be reinstated at a later date.

                      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