0

Can anyone explain what is the difference between object vs instance vs reference, with a good example?

I'm confused about this part:

  1. ( classA a;
    a = new classA(); )
  2. ( classA a;
    a = new classB(); )
  3. ( classA a;
    classB a = new classB(); )
Suresh Kumar Msk
  • 87
  • 1
  • 3
  • 10

2 Answers2

4

classA a is a reference variable.

new classA(); created Object / Instance

a = new classB() is assign object reference to variable

muzahidbechara
  • 253
  • 1
  • 14
0

ClassA a is reference

a = new ClassA() a object os asign reference to variable

2 a = new classB() is pass the reference of classB

3 Here classA is override becauseeyou set same same name of reference

Chirag Sondagar
  • 427
  • 1
  • 4
  • 15