0
using System; public class A { public A() { Console.WriteLine(this.GetHashCode()); Console.WriteLine("A Created"); } } public class B : A { public B() { Console.WriteLine(this.GetHashCode()); Console.WriteLine("B Created"); } } public class C { public static void Main(String[] args) { B t = new B(); } } 

Output: 1805487208 A Created 1805487208 B Created

Why i got the same address for these 2 objects. Actually these 2 objects must be created side by side . But how come we are getting the same address for these two objects???

16
  • 4
    There is only one object (B includes A; it is not separate from A). Why do you think there are two? Commented Feb 10, 2020 at 12:04
  • BTW, this question could be duplicated of stackoverflow.com/a/26615241/2265446 Commented Feb 10, 2020 at 12:09
  • 1
    @SakethKota, maybe you should read up on inheritance Commented Feb 10, 2020 at 12:26
  • 2
    Does this answer your question? Same GetHashCode() for different objects Commented Feb 10, 2020 at 12:39
  • 1
    What do you mean by "addresses"? Where did you check that any of these objects has an "address"? Commented Feb 10, 2020 at 12:43

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.