Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

What is a Reference Variable? How do we use it?

843785Jul 14 2008 — edited Jul 14 2008
Hi all,

This is another newbie question. Can you please explain what is a Reference Variable, and how to use it? For example, there is a reference variable called "Point origin" in the Rectangle Class.
public class Rectangle {
    public int width = 0;
    public int height = 0;
    public Point origin;
public class Point {
    public int x = 0;
    public int y = 0;

    public Point(int a, int b) {
	x = a;
	y = b;
    }
}
Some confusions that I have ~ :
1. How does the 'Rectangle class' know 'where' does the reference variable "Point origin;" come from?

2. Does "Point" refer to a 'class' called Point or to its 'constructor'?

3. What if inside the 'Point class{}', there are many constructors and methods? For example, method "doThis()" and "doThat()", then we use the Dot operator to call the doThis and doThat method, right? For e.g:- origin.doThis(); origin.doThat, is it correct?

Sorry for asking very basic questions here. Hopefully, some other beginners would like to know the answers too. :-)
Thank you!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 11 2008
Added on Jul 14 2008
9 comments
293 views