Results 1 to 2 of 2
Thread: very very noob queston
- 04-28-2012, 10:51 AM #1
Member
- Join Date
- Apr 2012
- Location
- Gujarat , India
- Posts
- 5
- Rep Power
- 0
very very noob queston
I am very very unexperienced and still learning basics of java programming language , pls not be strict with me. In the following code , I almost understood everything with exception of code in line 14 and 17 to 44! Pls tell me what they meant with that. Specially i didn't get meaning of used "origin" here. Thanks in advance. Origin really confusing me here.
Java Code:public class Point { public int x = 0; public int y = 0; // a constructor! public Point(int a, int b) { x = a; y = b; } } public class Rectangle { public int width = 0; public int height = 0; public Point origin; // four constructors public Rectangle() { origin = new Point(0, 0); } public Rectangle(Point p) { origin = p; } public Rectangle(int w, int h) { origin = new Point(0, 0); width = w; height = h; } public Rectangle(Point p, int w, int h) { origin = p; width = w; height = h; } // a method for moving the rectangle public void move(int x, int y) { origin.x = x; origin.y = y; } // a method for computing the area of the rectangle public int getArea() { return width * height; } }
Last edited by deepode; 04-28-2012 at 10:54 AM.
- 04-28-2012, 12:53 PM #2
Member
- Join Date
- Apr 2012
- Posts
- 59
- Rep Power
- 0
Re: very very noob queston
Point is a class, you can create one like above and call it whatever you want, in this case you've called it 'origin' but you could call it anything. In this case it's called origin because it holds information on where the Rectangle originates
Java Code:Point origin;
Java Code:origin.x = 100;
Now...
Java Code:public Rectangle()
Java Code:Rectangle myRectangle; //This is my variable (memory space) for holding a copy of a rectangle myRectangle = new Rectangle() //this is where the above method would be called, a new Rectangle is created and stored in the space 'myRectangle'
The 'move()' and 'getArea()' methods are inside the Rectangle class so they are part of it, we call them 'members of the Rectangle class' and it means they can be accessed when you have an instance (a created version) of a Rectangle, like so...
Java Code:int myArea = myRectangle.getArea();
Similar Threads
-
I am a super noob with a super noob question.
By LittleZoppo in forum Java AppletsReplies: 3Last Post: 04-27-2012, 04:50 AM -
Noob here
By Iron Lion in forum IntroductionsReplies: 1Last Post: 11-15-2010, 06:50 PM -
Very noob, but need help!!!
By Guilbertda in forum New To JavaReplies: 2Last Post: 02-01-2010, 11:32 PM -
Help im a noob.. a super noob on java..
By critdevil in forum New To JavaReplies: 12Last Post: 03-07-2009, 04:17 AM -
kindly answer the queston in attachment file
By abhinav_jain09 in forum Advanced JavaReplies: 11Last Post: 09-19-2008, 05:47 PM
Bookmarks