Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Illegal modifier for the constructor in type  class; only public, protected & private permitted Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Illegal modifier for the constructor in type  class; only public, protected & private permitted" Watch "Illegal modifier for the constructor in type  class; only public, protected & private permitted" New topic
Author

Illegal modifier for the constructor in type class; only public, protected & private permitted

Kaverappa Prabhakar
Ranch Hand

Joined: Aug 18, 2009
Posts: 43
Hello,

Recently I switched reluctantly to Eclipse Gallieo version Java EE IDE for Web Developers. Build id: 20090621-0832 from Oracle Jdevloper because management wanted me to do so. I do not hesitate to say Oracle Jdeveloper is a much better IDE tool than Eclipse.

Everything I had on Jdeveloper compiles and runs without any problem. I have a class called rePayClass and has a constructor shown below along with default constructor for this class. When I compile the code of this class in Eclipse it complains about the following :

"" Illegal modifier for the constructor in type rePayClass; only public, protected & private are permitted.""

One note worth mentioning here is that I have another class with similar structure I don't get any complaint about it.


Please let me know as soon as possible why eclipse IDE tool gives error message on the above constructor.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

The code you have posted has errors in it - you will not get it to compile with the Java compiler. If any IDE were to compile it then the IDE would be using it's own Java compiler, and that compiler would be faulty.

You have a class named rePayClass, a constructor named rePayClass, and what appears to be a constructor named repaySchedClass. That later constructor does not match the class name, and as such it is illegal in that context.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Kaverappa Prabhakar
Ranch Hand

Joined: Aug 18, 2009
Posts: 43
Andrew Monkhouse,

I apologize to you for my mistake. In the actual code I used repaySchedClass as the class name but I shorten it by naming it rePayClass. I was going to edit it but you answered it in a lightning speed. It is the fact that Eclipse does gives compilation error for the code shown below. Here is the corrected code:




Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

The problem we have is that when you provide different code to what you have in your editor then we are going to be responding to different issues.

How do I know that you have different code in your editor? Simple: the code posted does not declare the variables that are assigned to in lines 11 & 12. If you try to put that into Eclipse you will get an error on the assignment to the variable long before Eclipse starts looking at warnings about scope.
Kaverappa Prabhakar
Ranch Hand

Joined: Aug 18, 2009
Posts: 43
Indeed I have declared the instance variables of lines 11 and 12 in the actual code but I referred to it in the code block below as // declaration of class attributes goes here . I agree I should have been precise by giving the declaration of instance variables. You are right I would have got undeclared variable errors even before the constructor error.

Prabhakar

**********************************

// constructor for class rePayClass

public rePayClass(int max) {
progBorr = new String[max][2]; //prgoramId and BorrCode
loan = new int[max][2]; //commSeq and loanId
}
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
So does this mean that your problem is solved, that you have no more errors? If so, please let us know. If not, please provide us with a small compilable runnable program if possible that shows your problem, or if a compile error than the smallest program that we can test and that reproduces the compilation error.

Much luck!
Kaverappa Prabhakar
Ranch Hand

Joined: Aug 18, 2009
Posts: 43
Pete and Andrew,

What I did is that I deleted the java applicaion from Eclipse and remigrated the java application from Oracle Jdeveloper to Eclipse again. This corrected the comilation error problem I had.

Thank you both very much for you time and efforts.

Prabhakar
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

By seeing the TOPIC name i am just wondering how this could be a error.
Because all the three are allowed(individually not together) to use with the constructor.

SCJP6.0,My blog Ranchers from Delhi
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Naming a class with a lower-case first letter would be confusing and misleading to most Java developers, as it does not follow class naming convention.
 
 
subject: Illegal modifier for the constructor in type class; only public, protected & private permitted
 
Similar Threads
Constructors
constructors for Enum types....
Illegal modifier for parameter
Enum Constructor - Exception and Accessibility
A constructor cannot be final, static or abstract. Why ?