Article View: borland.public.jbuilder.java.api
Article #2227Re: How Static method is created by compiler?
From: Dave Bird
Date: Sat, 28 Apr 2001 16:25
Date: Sat, 28 Apr 2001 16:25
39 lines
2004 bytes
2004 bytes
In article <3aea6aff_2@dnews>, Frajola <fra_jo_la@ig.com.br> writes
>Friends,
>
>I think that a static method can be call
>without to criate the instance of the
>class.
>
>Why?
>
>Because the compiler identify if the
>class have a static method and create
>that instance of this class?
Static variables exist once per class and do not belong to any
particular instance. Static methods likewise exist once per
class and do not attach to any particular instance (so they
can't change variables of the "current instance"; they don't have one).
An example might be a variable to count the number of instances created,
and a method to issue each new instance.
class Node {
integer leftVal;
integer riteVal;
Node leftSon;
Node riteSon;
Node(){
leftVal=riteVal=0; leftSon=rireSon=null;
};
//
static integer numNodes = 0;
static Node issueNode(){ ++numNodes;
return new Node();
};
};
--
^-^-^-@@-^-;-^ http://www.xemu.demon.co.uk/
(..)__u news:alt.smoking.mooses
Technical Details
Message-ID:
<t5HJbADW8u66Ewmp@xemu.demon.co.uk>Path:
arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!dispose.news.demon.net!news.demon.co.uk!demon!xemu.demon.co.uk!daveReferences:
<3aea6aff_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,5d083c96572bdeed X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2001-04-28 09:34:01 PST Path: arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!dispose.news.demon.net!news.demon.co.uk!demon!xemu.demon.co.uk!dave From: Dave Bird <dave@xemu.demon.co.uk> Newsgroups: borland.public.jbuilder.java.api Subject: Re: How Static method is created by compiler? Date: Sat, 28 Apr 2001 17:25:58 +0100 Organization: none Message-ID: <t5HJbADW8u66Ewmp@xemu.demon.co.uk> References: <3aea6aff_2@dnews> NNTP-Posting-Host: xemu.demon.co.uk X-NNTP-Posting-Host: xemu.demon.co.uk:158.152.196.209 X-Trace: news.demon.co.uk 988475489 nnrp-08:20233 NO-IDENT xemu.demon.co.uk:158.152.196.209 X-Complaints-To: abuse@demon.net MIME-Version: 1.0 X-Newsreader: Turnpike Integrated Version 5.00 U <dQumtnY$x4rJ2u5tL5fS$n2vuP> Lines: 39