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

Thread: Question regarding objects

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Question regarding objects

    Hello everyone!

    I'm a relatively newcommer to the programming experience, with a bit of knowledge in C++ and beginners Java.

    I need help in an assignment of mine, which requires me to create a circle class and circle object, with a getradius method.

    My teacher has provided a sample code:

    public class Main
    {
    public static void main (String[] args)
    {
    // defines Circle object;
    // call helper(class) method to input the radius
    // instantiate the Circle object;
    // output the circumference using instance method
    // output the area using instance method
    }
    public static __________ getRadius()
    {
    // define a local radius variable
    // read in a value for radius
    // return the value
    }
    }
    -----Circle.java--------------
    public class Circle {

    double radius;

    public Circle(double rad)
    {
    radius = rad;
    }

    public double getRadius()
    {
    return radius;
    }

    public double getDiameter()
    {
    return 2.0*radius;
    }

    public double getCircumference()
    {
    return 2.0*Math.PI*radius;
    }

    public double getArea()
    {
    return Math.PI*radius*radius;
    }

    }

    My question is:

    1) the public class method is the actual circle object?
    2) how do i define a circle object?
    3) how do i instantiate the circle object?
    4) and what are instance methods? How do I output results using an instance method?



    I posted this on the theory section, but need an immediate answer.


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Question regarding objects

    These are all very basic Java questions, so I recommend you do some background research as the next Java assignment I suspect is going to be a tad harder.

    Suggested Reading:
    Understanding Instance and Class Members (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    and
    Lesson: Classes and Objects (The Java™ Tutorials > Learning the Java Language)



    Edit: So why have you opened another thread on these forums asking the same question? This is against forum rules and you should refrain from doing so in the future.
    This thread will surely be locked soon.

    Please stick to the original thread:
    http://www.javaprogrammingforums.com...p-objects.html
    Last edited by newbie; September 10th, 2012 at 05:27 PM.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Question regarding objects

    Thread locked as duplicate.

Similar Threads

  1. Need help on objects
    By alex067 in forum Java Theory & Questions
    Replies: 4
    Last Post: September 10th, 2012, 06:23 PM
  2. [Question] Objects instantiated within objects.
    By Xerosigma in forum Object Oriented Programming
    Replies: 6
    Last Post: April 25th, 2012, 10:53 AM
  3. Question Dynamically create objects, set value and call
    By buntyindia in forum Java Theory & Questions
    Replies: 1
    Last Post: May 25th, 2011, 07:50 AM
  4. java question on objects
    By joe98 in forum Threads
    Replies: 2
    Last Post: April 12th, 2011, 03:54 PM
  5. New to Objects...
    By Java Neil in forum What's Wrong With My Code?
    Replies: 17
    Last Post: March 24th, 2011, 07:00 AM