Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

constructor overloading problem  RSS feed

 
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
Marshal
Posts: 5322
575
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: 9608
36
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
Sheriff
Posts: 22818
119
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
Boost this thread!