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


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

Re: Instantiation of a class

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!news-out.readnews.com!news-xxxfer.readnews.com!postnews.google.com!z7g2000prh.googlegroups.com!not-for-mail
From lewbloch <lewbloch@gmail.com>
Newsgroups comp.lang.java.help
Subject Re: Instantiation of a class
Date Mon, 11 Jul 2011 16:41:48 -0700 (PDT)
Organization http://groups.google.com
Lines 36
Message-ID <a9ca683a-c0f2-4eaa-8cda-876ecec817f3@z7g2000prh.googlegroups.com> (permalink)
References <d98a873f-d5db-4243-be26-2109c25744b2@q12g2000prb.googlegroups.com>
NNTP-Posting-Host 172.19.62.231
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-Trace posting.google.com 1310427708 15279 127.0.0.1 (11 Jul 2011 23:41:48 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Mon, 11 Jul 2011 23:41:48 +0000 (UTC)
Complaints-To groups-abuse@google.com
Injection-Info z7g2000prh.googlegroups.com; posting-host=172.19.62.231; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-Header-Order ASELCHRU
X-HTTP-UserAgent Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1,gzip(gfe)
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.help:845

Show key headers only | View raw


On Jul 11, 4:03 pm, Fred <albert.xtheunkno...@gmail.com> wrote:
> Hello,
>
> I'm thinking about statements like String foo = new String("foo");
> When is the constructor specified not the name of the type of
> reference variable?
>

You specify the constructor when you want to create a new (hence the
'new' keyword) instance of a class.

The constructor for a class always has the same name as the class, and
is declared similarly to a method but without a return type:

 public class Foo
 {
   public Foo()
   {
   }
 }

This information is in the tutorials and in the JLS (Java Language
Specification).  Whenever you have a basic question about Java like
this, the tutorials are a good place to start.

http://download.oracle.com/javase/tutorial/
<http://download.oracle.com/javase/tutorial/java/javaOO/
constructors.html>
et seq.

http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html
<http://java.sun.com/docs/books/jls/third_edition/html/
classes.html#8.8>

--
Lew

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


Thread

Instantiation of a class Fred <albert.xtheunknown0@gmail.com> - 2011-07-11 16:03 -0700
  Re: Instantiation of a class lewbloch <lewbloch@gmail.com> - 2011-07-11 16:41 -0700
    Re: Instantiation of a class lewbloch <lewbloch@gmail.com> - 2011-07-11 16:54 -0700
  Re: Instantiation of a class Mayeul <mayeul.marguet@free.fr> - 2011-07-12 02:02 +0200
  Re: Instantiation of a class Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-11 21:57 -0400
    Re: Instantiation of a class Patricia Shanahan <pats@acm.org> - 2011-07-11 19:02 -0700
      Re: Instantiation of a class Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-11 22:10 -0400
    Re: Instantiation of a class Fred <albert.xtheunknown0@gmail.com> - 2011-07-11 20:29 -0700
      Re: Instantiation of a class lewbloch <lewbloch@gmail.com> - 2011-07-12 14:35 -0700
    Re: Instantiation of a class Gene Wirchenko <genew@ocis.net> - 2011-07-11 21:25 -0700
      Re: Instantiation of a class Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-12 07:47 -0400
        Re: Instantiation of a class lewbloch <lewbloch@gmail.com> - 2011-07-12 11:09 -0700

csiph-web