Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Instance method

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    22
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default Instance method

    public class Rectangle {
    private final int width = 0;
    private final int height = 0;
    public Point origin;

    // use:
    public Rectangle() {
    origin = new Point(0, 0);

    //use
    }
    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;
    }

    //
    public void move(int x, int y) {
    origin.x = x;
    origin.y = y;
    }

    //
    public int getArea() {
    return width * height;
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Instance method

    cannot find symbol
    The compiler can not find the variable or method named in the error message. Check that it exists and is spelled correctly.

    double cannot be dereferenced
    primitives do NOT have methods.
    int x = 1;
    x.getIt(); //  illegal, int do not have methods

    Check if there is a reference to a instance of a class that should be used where the double is.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    JohnJohnson123 (October 27th, 2013)

  4. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    22
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default Re: Instance method

    Thanks Norm.

    I don't get it. I'm trying to turn x into a string. And x is all over the place.

    There are a lot of problems in this code.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Instance method

    turn x into a string
    To make x a String, put it in "s
    String anX = "x"; // put x in a String
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    JohnJohnson123 (October 27th, 2013)

Similar Threads

  1. Instance variable inside a method
    By mstratmann in forum Object Oriented Programming
    Replies: 20
    Last Post: May 5th, 2013, 07:46 PM
  2. Need to write a public instance method for a simple dice program
    By akira25 in forum Object Oriented Programming
    Replies: 3
    Last Post: April 9th, 2012, 04:46 AM
  3. "Static method cannot hide instance method from implemented Interface"
    By Gthoma2 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 21st, 2011, 03:03 AM
  4. [SOLVED] static variable in an instance method?
    By chronoz13 in forum Java Theory & Questions
    Replies: 2
    Last Post: January 30th, 2010, 03:24 AM
  5. Creating new instance
    By vluong in forum Object Oriented Programming
    Replies: 2
    Last Post: November 28th, 2009, 11:35 PM