Meaningless Drivel is fun!*
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "constructor overloading problem" Watch "constructor overloading problem" New topic
Author

constructor overloading problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634




errors-

------------------------------------------------------------------


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: 3060
    
  38

'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
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

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
author
Sheriff

Joined: Sep 28, 2004
Posts: 18764
    
  40


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

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: constructor overloading problem