Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6574091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:13:00+00:00 2026-05-25T15:13:00+00:00

We are learning how to use multiple classes in Java now, and there is

  • 0

We are learning how to use multiple classes in Java now, and there is a project asking about creating a class Circle which will contain a radius and a diameter, then reference it from a main class to find the diameter. This code continues to receive an error (mentioned in the title)

public class Circle
{
    public CircleR(double r)
    {
        radius = r;
    }
    public diameter()
    {
        double d = radius * 2;
        return d;
    }
}

Thanks for any help, -AJ

Update 1:
Okay, but I shouldn’t have to declare the third line public CircleR(double r) as a double, right? In the book I am learning from, the example doesn’t do that.

public class Circle 

    { 
        //This part is called the constructor and lets us specify the radius of a  
      //particular circle. 
      public Circle(double r) 
      { 
       radius = r; 
      } 

      //This is a method. It performs some action (in this case it calculates the 
        //area of the circle and returns it. 
        public double area( )  //area method 
      { 
          double a = Math.PI * radius * radius; 
       return a; 
    } 

    public double circumference( )  //circumference method 
    { 
      double c = 2 * Math.PI * radius; 
     return c; 
    } 

        public double radius;  //This is a State Variable…also called Instance 
         //Field and Data Member. It is available to code 
    // in ALL the methods in this class. 
     } 

As you can see, the code public Circle(double r).... how is that different from what I did in mine with public CircleR(double r)? For whatever reason, no error is given in the code from the book, however mine says there is an error there.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:13:00+00:00Added an answer on May 25, 2026 at 3:13 pm

    As you can see, the code public Circle(double r)…. how is that
    different from what I did in mine with public CircleR(double r)? For
    whatever reason, no error is given in the code from the book, however
    mine says there is an error there.

    When defining constructors of a class, they should have the same name as its class.
    Thus the following code

    public class Circle
    { 
        //This part is called the constructor and lets us specify the radius of a  
        //particular circle. 
      public Circle(double r) 
      { 
       radius = r; 
      }
     ....
    } 
    

    is correct while your code

    public class Circle
    {
        private double radius;
        public CircleR(double r)
        {
            radius = r;
        }
        public diameter()
        {
           double d = radius * 2;
           return d;
        }
    }
    

    is wrong because your constructor has different name from its class. You could either follow the same code from the book and change your constructor from

    public CircleR(double r) 
    

    to

    public Circle(double r)
    

    or (if you really wanted to name your constructor as CircleR) rename your class to CircleR.

    So your new class should be

    public class CircleR
    {
        private double radius;
        public CircleR(double r)
        {
            radius = r;
        }
        public double diameter()
        {
           double d = radius * 2;
           return d;
        }
    }
    

    I also added the return type double in your method as pointed out by Froyo and John B.

    Refer to this article about constructors.

    HTH.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning to use LabVIEW as part of my honours project, and was
I have been learning to use Emacs for a little while now. So far
I am learning how to use NUnit. I have my main project in it's
I am interested in using/learning RoR in a project where I have to use
I've been learning SQL for about a day now and I've run into a
I've only started learning Java about 3 months ago and this is my first
I am learning to use polymorphism in C#, but cannot figure out this one.
I am learning to use the Dvorak keyboad layout, but I am not good
I'm learning how to use Greasemonkey, and was wondering what the @namespace metadata id
Where is a good place to get started learning how to use jQuery? It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.