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


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

Re: Instantiation of a class

From lewbloch <lewbloch@gmail.com>
Newsgroups comp.lang.java.help
Subject Re: Instantiation of a class
Date 2011-07-11 16:41 -0700
Organization http://groups.google.com
Message-ID <a9ca683a-c0f2-4eaa-8cda-876ecec817f3@z7g2000prh.googlegroups.com> (permalink)
References <d98a873f-d5db-4243-be26-2109c25744b2@q12g2000prb.googlegroups.com>

Show all headers | 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