This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

constructor overloading problem

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4518
280
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'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);
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]
 
Henry Wong
author
Marshal
Pie
Posts: 21220
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic