• Post Reply Bookmark Topic Watch Topic
  • New Topic

super newbie question  RSS feed

 
Renato Bello
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this example:




Dog (object?) in the class DogTester is referencing the class Dog or whatever?

Thanks
 
Daryl Cofer
Greenhorn
Posts: 19
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your class DogTester, when you say "Dog d = new Dog();" you are creating a Dog object that is stored under the variable d. So to answer your question, yes.
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Renato Bello wrote:Dog (object?) in the class DogTester is referencing the class Dog or whatever?

1) Dog is a class, not an object.
2) 'd' is referring to an object of Dog class.
Daryl Cofer wrote:you are creating a Dog object that is stored under the variable d

No. Dog object is created and stored under heap. A reference 'd' refers to that object.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's look at line 9 of your code: Dog d = new Dog();

You are declaring a variable with the name 'd'.

Variables have a type. The type of the variable 'd' is 'Dog'.

Dog is a class. A class is a 'template' from which you create objects. On the right side of line 9 (after the =), you create a new Dog object. Then you assign that to the variable 'd', so 'd' now refers to the new Dog object.

After that, you use the variable 'd' to do things with the new Dog object that you created. For example, in line 10, you set the value of one of the properties of the Dog object.
 
Renato Bello
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everybody.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!