Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Jim Janney Newsgroups: comp.lang.java.programmer Subject: Re: It doesn't like 'super' where ever I put it. Date: Sun, 10 Jun 2012 10:26:44 -0600 Organization: dotting one eye and crossing the other Lines: 39 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx04.eternal-september.org; posting-host="dZdavj/jUDynNQgDq5jkeA"; logging-data="9074"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX188x3EtwDs/S8eAbZV28etW" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:AkHthC2RkILOQS1RVyz7NC12+6A= sha1:nBxchMgti1rAoBWd45FwH2npx10= Xref: csiph.com comp.lang.java.programmer:15177 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. -- Jim Janney