wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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\MyTest.java:37: unclosed character literal
new b('a1');
C:\Users\mohit\Documents\Jcreator FIles\MyTest.java:37: ';' expected
new b('a1');
C:\Users\mohit\Documents\Jcreator FIles\MyTest.java:37: 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: 3013

'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);

Founder of ExamLab and Systemup
See how I can help you to become an awesome programmer
Ankit Garg

Joined: Aug 03, 2008
Posts: 9291

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: 18507

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)
It is sorta covered in the JavaRanch Style Guide.
subject: constructor overloading problem
Similar Threads
Compile time Difference between // and /* */
Question On Comparator
unicode character
overloading and overriding in class problem
Order Of Constructor calling