Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1019

Re: Java class constructor method

From Eric Sosman <esosman@ieee-dot-org.invalid>
Newsgroups comp.lang.java.help
Subject Re: Java class constructor method
Date 2011-09-07 07:48 -0400
Organization A noiseless patient Spider
Message-ID <j47lmg$eve$1@dont-email.me> (permalink)
References <5fdf778b-5252-4cbe-8e9a-bfd969796579@br5g2000vbb.googlegroups.com>

Show all headers | View raw


On 9/7/2011 2:32 AM, Cleaver Greene wrote:
> Why doesn't this line compile? The constructor indicated by<<!!>>
> returns a "cannot find symbol" error.
> [...]
>        //declare and instantiate a television object
>        Television bigScreen = new Television("Toshiba",
> 55);<<!!>>
> [...]
>      /**
>       * Constructor for objects of class Television
>       */
>      public Television(char tvMANUFACTURER, int tvSCREEN_SIZE)
>      {

     Because "Toshiba" is not a char.  'T' would be a char, or
"Toshiba".charAt(3), but "Toshiba" is not a char.

     At the line where the error is reported, you are suppyling a
String and an int as arguments to the Television constructor.  Java
rummages through the Television class, looking for a constructor
whose parameters match those arguments.  Your Television class has
no such constructor (because a String cannot be converted to a char),
so Java reports trouble.

     The text of the report is perhaps confusing to a newcomer, who
may be wondering "Why doesn't it just tell me my arguments are of
the wrong type?"  Recall, though, that a Java class may have several
constructors, distinguished only by their parameter lists.  From
Java's viewpoint, it's not that your arguments don't match "the"
constructor's parameters, but that none of the (potentially many)
constructors have a parameter list that matches your arguments.  The
same thing, pretty much, happens with overloaded methods, where a
class may have several methods with the same name and different
parameter lists.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

Back to comp.lang.java.help | Previous | NextPrevious in thread | Find similar


Thread

Java class constructor method Cleaver Greene <thybutcher@gmail.com> - 2011-09-06 23:32 -0700
  Re: Java class constructor method Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-07 07:48 -0400

csiph-web