• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

super newbie question

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this example:




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

Thanks
 
Greenhorn
Posts: 19
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you everybody.
 
reply
    Bookmark Topic Watch Topic
  • New Topic