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(); )
2
  • why the random tags? Commented Apr 28, 2016 at 6:12
  • Reference points to an instance of an object. Commented Apr 28, 2016 at 6:14

2 Answers 2

4

classA a is a reference variable.

new classA(); created Object / Instance

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

Sign up to request clarification or add additional context in comments.

2 Comments

Then what is classA a; classB a = new classB();
Its actually 2 statement - classA a; is a statement just declared reference variable without assignment. and classB a = new classB(); is a statement with assigment
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.