Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Bob Graffagnino
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the compiler say? It doesn't like it, uh?
[ February 14, 2002: Message edited by: Valentin Crettaz ]
 
Brian Lugo
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then I apologize for my comments
Good luck and come back with some good news
 
Brian Lugo
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian, are you trying to corrupt me?
 
Brian Lugo
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup I'll buy you couple of Beers

I gotcha
 
Bob Graffagnino
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic