Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: bilsch Newsgroups: comp.lang.java.programmer Subject: Re: It doesn't like 'super' where ever I put it. Date: Sun, 10 Jun 2012 13:17:14 -0700 Organization: A noiseless patient Spider Lines: 39 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 10 Jun 2012 20:17:14 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="llALXQ6TxsVqIoSLcrwVyA"; logging-data="3157"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Evp8nODElMYNQqcRQdm4U" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 In-Reply-To: Cancel-Lock: sha1:2k7NRd2BYSFxWndnWpEFoaLVj+o= Xref: csiph.com comp.lang.java.programmer:15194 On 6/10/2012 9:26 AM, Jim Janney wrote: > bilsch writes: > >> On 6/10/2012 7:02 AM, Jim Janney wrote: >>> bilsch writes: >>>> BUILD SUCCESSFUL (total time: 2 seconds) >>> >>> Try changing >>> >>> public void CalcFrame1() { >>> >>> to >>> >>> public CalcFrame1() { >>> >> OK. Thanks. Can you tell me why that makes a difference? > > Constructors are fundamentally different from ordinary methods, so most > object-oriented languages use a different syntax for them. In Java, a > constructor definition looks like a method, but without an explicit > return type and using a name that matches the class name. In other > languages the syntax may be different -- for example, in Python the name > is always __init__ -- but the underlying idea is the same: constructors > are not ordinary methods and take a different syntax. > > Why are constructors different? Most classes have some code that you > want to run whenever a new object is created, and it would be tedious to > have to call it explicitly every time. I used to mimic OOP in C and you > had to do things like > > struct Foo* foo = (struct Foo*) malloc(sizeof(struct Foo)); > foo->init(); > > Forcing all object creation to go through a constructor makes the code > simpler and more reliable. And even when a class has a constructor that > appears to be empty, there's still some code that the compiler generates > automatically the make the new object a proper instance of its class. > Thanks for the info.