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 7 of 7

Thread: Creating an object...

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Creating an object...

    Hello all, java noob here.
    Now I'm going through the book and it is going well so far, however, one thing I just don't understand is how to create an object.

    For example, say I want to make an object about squares.

    The syntax would be,

    Squares squares = new Squares();

    correct?

    When I make a program with this format, I will get error messages saying
    cannot find symbol
    symbol: class Squares
    location: class (whatever the class would be)

    Note this isn't an actual example from a program I have written, just an example I made up with the same error messages.


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Creating an object...

    You have to write the Squares class. Programming does not happen by magic. Also be careful of how you name your classes. Squares suggest it will hold information about many squares. Whereas Square suggests that it will hold information about a single square.

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Creating an object...

    Okay I am already lost, mind pointing me in the right direction for making the class?

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Creating an object...

    Squares squares = new Squares();
    Where is that line of code? I assume it is in a main method inside a class you have written. So you already know how to write a class.

  5. #5
    Junior Member
    Join Date
    Jun 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Creating an object...

    Hi RodePope4546,
    the syntax you are using to create the object is correct. You just need to make sure the code to use Squares class have access to Squares class. I mean, the class which have following code,
    Squares squares = new Squares();
    should either be in the same package or have import the package which contains the Squares class.

    Hope this will resolve the issue!

  6. #6
    Junior Member
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Creating an object...

    write Squares class according to your program and make sure it is visible to class in which statement Squares squares = new Squares(); is written as suggested by java_I3.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Creating an object...

    direction for making the class?
    A class is defined by the class keyword.
    class MySquares {
    ... here define the stuff for the class
    } // end class definition

Similar Threads

  1. Calling from one javabean object to other javabean object in a single class
    By kichkich in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 24th, 2011, 07:20 AM
  2. Creating Servlet object
    By tcstcs in forum Java Servlet
    Replies: 3
    Last Post: May 9th, 2011, 02:13 AM
  3. [SOLVED] Creating a .jar that uses a DB
    By mycallsevern in forum JDBC & Databases
    Replies: 2
    Last Post: May 8th, 2011, 10:43 AM
  4. Reading from ResultSet to Object and from object Object Array
    By anmaston in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 7th, 2011, 06:11 AM
  5. 2D Object makes my object smaller, Why?
    By MassiveResponse in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 15th, 2010, 02:33 PM