1

I am student learning about java.While solving problems I faced the issue.I want to know what is difference between these two statements.

-The second statement is declaration of new object.

-I don't know about the first statement and difference between two statements.

Also plz let me know when to use both the statements.

If Person is class in java,then what is difference between

  1. Person p;

  2. Person p = new Person();

azro
  • 53,056
  • 7
  • 34
  • 70

1 Answers1

3

Person p; means you create a variable with no person object. But Person p = new Person(); means you create a variable and reference it a person object

Just_Me
  • 111
  • 8
  • Thanks,can you plz tell when to use first statement and when to use second statement?Please elaborate about the first statement & specially when to use it. – Onkar Bhalke Mar 15 '20 at 16:42
  • I cant remember that have i ever used the first one so i think it is not very important to use – Just_Me Mar 22 '20 at 20:42