• Register
1 vote


Well, I am a new student of java programming. Nowadays I am learning how to use multiple classes in a java program. Based on my learning I’ve written a code that gave me an error, “Invalid method declaration; return type required

I am attaching the snippet here:

public class Circle 
      public CircleR(double r) 
       radius = r; 

        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;

Can you, please tell me where I am doing the wrong thing?

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

2 votes


When defining constructors of a class, they should have the same name as its class. You are getting the error because your constructor has a different name from its class.

To run the program error-free you need to change the class name or the constructor name.  

public CircleR(double r)

to the constructor name

public Circle(double r)

or the class name from:

public class Circle


public class CircleR

Keep discovering new things. Thanks

13 9 6
94,240 points

Related questions

0 votes
1 answer 13 views
Problem: On a Java OOP project I got three errors on my constructor: .\Voter.java:14: error: invalid method declaration; return type required .\Candidates.java:7: error: invalid method declaration; return type required .\Candidates.java:14: error: invalid method declaration; return type required
asked Feb 17 Ali 4.8k points
0 votes
1 answer 12 views
Problem: Hello there! I am working with C# in Visual Studio and I am learning user-defined functions in C#. When I try to execute my program, it throws an error that says method must have a return type. I have checked my function and I find nothing wrong with it. ... ;t know what’s the problem and what should I do. If someone could tell me, that would be a big favor. Thanks in advance
asked Oct 16, 2020 Code Learner 6k points
0 votes
1 answer 49 views
Anything I missed?
asked Dec 19, 2020 TeamScript 13.5k points
1 vote
2 answers 37 views
Problem: Hello java programmers, Myself is a new student in java. I am practicing basic java methods and objects. Finding beginner-level problems and trying to solve them. I recently got a line that says, all local variables in a method have default values. What does it mean? Can you please write a simple code that makes me understand this well? Thanks guys.
asked Mar 26, 2020 Gavin 15.3k points
1 vote
2 answers 68 views
Problem: Hello Kodlogs, I have a simple java code that I wrote a few minutes back I was trying to compare numbers using methods. The program throws the error again and again: this method must return a result of type int. I couldn’t figure out the problem. Could you please shed some light on this ... []) { int x = 8; int y = 9; int z = 20; System.out.println(largest(x, y, z)); } } Many thanks
asked Mar 27, 2020 Gavin 15.3k points
0 votes
1 answer 4 views
Problem: It compiles but JVM fails in runtime with the following error: Exception in thread "main" java.lang.VerifyError: Bad return type.ries to start, then crashes and it get this: This crashed whilst initializing game Error: java.lang.VerifyError: Bad return type I try to view crash report. >Can someone please help fix this
asked 5 days ago Ali 4.8k points
0 votes
1 answer 105 views
Problem: Hi there! I am a bit curious about what happens if I skip the return type in function declaration. Does the compiler generate error or the program executes normally? If it executes normally, what return type is used as function return type by default?
asked Nov 28, 2020 Code Learner 6k points
0 votes
1 answer 8 views
Problem: When I try to compile this: import java.awt.* ; class obj { public static void printPoint (Point p) { System.out.println ("(" + p.x + ", " + p.y + ")"); } public static void main (String[]arg) { Point blank = new Point (3,4) ; System.out. ... (blank)) ; } } I don't really know how to start asking about this other than to ask: What went wrong here? What does this error message mean?
asked Feb 17 Ali 4.8k points
1 vote
1 answer 103 views
Problem: I am a new Java programmer who is learning new things every day throughout doing the wrong things I have a giant piece of java code that I wrote for my practise. A certain portion of my code is generating an error and saying Error: 'void' type not allowed here. Why ... a close look into it and let me know if you can find out any problem with it. I can’t wait to hear from you. Thanks
asked Apr 26, 2020 Gavin 15.3k points
0 votes
1 answer 1 view
1 view
Problem: How do you create an instance method in Java? What does an instance method of a class represent? What is another name for an instance method? What is the difference between instance method and class method in Java? Can anyone have ideas to explain in detail?
asked 4 hours ago Ali 4.8k points