Results 1 to 2 of 2
  1. #1
    deepode is offline Member
    Join Date
    Apr 2012
    Gujarat , India
    Rep Power

    Unhappy 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.

  2. #2
    k1ng is offline Member
    Join Date
    Apr 2012
    Rep Power

    Default 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;
    then use anything that is public inside it like

    Java Code:
    origin.x = 100;
    and you can pass it around like a variable.

    Java Code:
    public Rectangle()
    is called a 'constructor' method. It's inside a difference Object called Rectangle. If a method has the same name as the class it's in then it's a constructor and it means anytime you make a new version of that class, this method is called automatically. For example...

    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'
    You can have many different 'constructors' in a class, this is called 'overloading' and they have to have different arguments (the bit in brackets). This is so that you can create the object in different ways.
    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();
    this would set 'myArea' to the area of myRectangle.

Similar Threads

  1. I am a super noob with a super noob question.
    By LittleZoppo in forum Java Applets
    Replies: 3
    Last Post: 04-27-2012, 04:50 AM
  2. Noob here
    By Iron Lion in forum Introductions
    Replies: 1
    Last Post: 11-15-2010, 06:50 PM
  3. Very noob, but need help!!!
    By Guilbertda in forum New To Java
    Replies: 2
    Last Post: 02-01-2010, 11:32 PM
  4. Help im a noob.. a super noob on java..
    By critdevil in forum New To Java
    Replies: 12
    Last Post: 03-07-2009, 04:17 AM
  5. kindly answer the queston in attachment file
    By abhinav_jain09 in forum Advanced Java
    Replies: 11
    Last Post: 09-19-2008, 05:47 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts