Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes constructor overloading problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "constructor overloading problem" Watch "constructor overloading problem" New topic

constructor overloading problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634



C:\Users\mohit\Documents\Jcreator FIles\ unclosed character literal
new b('a1');
C:\Users\mohit\Documents\Jcreator FIles\ ';' expected
new b('a1');
C:\Users\mohit\Documents\Jcreator FIles\ unclosed character literal
new b('a1');
3 errors

Process completed.

even if i replace the line "new b('a1');" with "new b('21');",error still occurs

OCPJP 6.0 93%
OCPJWCD 5.0 98%
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3389

'a1' or '21' are not legal values in Java. If you are passing a char value, there should be only one character, like 'a' or 'b'.
If you are passing an int value, you should not use single quotes for that. Try using new b(21);

Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Ankit Garg

Joined: Aug 03, 2008
Posts: 9327

You can't put two characters inside of single quotes. I'm not sure why you are passing your constructor a char value when it accepts an int, but if you do want to do it, then try new b('1'); or new b('2');...

[Edit: beaten by 23 seconds]

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Henry Wong

Joined: Sep 28, 2004
Posts: 19534

Or in other words, these are syntax errors... not errors related to overloading constructors.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
subject: constructor overloading problem