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.
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
Re: Question regarding objects
Thread locked as duplicate.