GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Possible for constructors to have different access modifiers & same param lists? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Possible for constructors to have different access modifiers & same param lists?" Watch "Possible for constructors to have different access modifiers & same param lists?" New topic
Author

Possible for constructors to have different access modifiers & same param lists?

Bob Graffagnino
Ranch Hand

Joined: May 30, 2001
Posts: 81
Is it possible to have a class with 2 constructors that take an int. One is public and the other is private.
class MyClass{
public MyClass(int i){}
private MyClass(int i){}
}
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
What does the compiler say? It doesn't like it, uh?
[ February 14, 2002: Message edited by: Valentin Crettaz ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Brian Lugo
Ranch Hand

Joined: Nov 10, 2000
Posts: 165
No, that is not possible. That is incorrect overloading. This applies to any method declared in the class too. You get the following error
message when you compile the code:
"Duplicate method declaration: MyClass(int)"
[ February 14, 2002: Message edited by: Brian Lugo ]
Bob Graffagnino
Ranch Hand

Joined: May 30, 2001
Posts: 81
I'm at the test center now, so I didn't have access to a compiler. I may as well get this over with <gulp!>.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Then I apologize for my comments
Good luck and come back with some good news
Brian Lugo
Ranch Hand

Joined: Nov 10, 2000
Posts: 165
Does the test center have internet access?
Which one is it? I will try to go to the same test center, Valentin will you help me when I am taking the test at that test center?
-- Brian
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Brian, are you trying to corrupt me?
Brian Lugo
Ranch Hand

Joined: Nov 10, 2000
Posts: 165
Yup I'll buy you couple of Beers
Bob - you need to relax right now. Don't think too much. Also, try to utilize full 2 hours of the test. Revise, Revise, Revise!! if you finish early and have some time left - Goodluck!
-- Brian
[ February 14, 2002: Message edited by: Brian Lugo ]
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Yup I'll buy you couple of Beers

I gotcha
Bob Graffagnino
Ranch Hand

Joined: May 30, 2001
Posts: 81
The test center only had internet access in their break room. No such luck in the examination room. I passed BTW with a 79%. I'll write more in the Certification results forum.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Possible for constructors to have different access modifiers & same param lists?