• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

overLoading

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference between reference type and object type.
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Left side will determine reference type, and right side will determine object type.
So in this case you have Animal reference to object of type Dog.

in this case you have Animal reference to object of type Animal.

and here you have Dog reference to object of type Dog.
 
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yggdrasill, your name doesn't confirm to the JavaRanch's naming policy..
Precisely it should be a combination of your first name and last name separated by spaces. Please chnge it by following this link.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this JavaRanch Campfire story: Cup Size -- a story about variables
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rani Nal,
Welcome to Javaranch.

A reference to an object is simply some fixed-size value that refers to the object in some way. It is the left hand side of an assignment.


In the preceding line the refrence type is Animal(which in itself is also a class/interface). Now, you can assign any subtype to a parent refrence type.

The object type on the other hand is the actual object that the refrence points to or holds. e.g. in preceding code the object type is of Dog.

Well, at compile time you can assign any subclass object type to supertype refrence. The actual capabilities of the object are checked at runtime.

Hope that helps.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

the refrence type will create on stack, but object type will create on heap.
 
snakes are really good at eating slugs. And you wouldn't think it, but so are tiny ads:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic