• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

super class where?

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

C:\JAVA>javac Test.java
Test.java:7: Can't reference a before the superclass constructor has been
called.
this(a);
^
1 error
Why it is accessing for superclass constructor?
thanks in advance
payal
[This message has been edited by payal sharma (edited July 27, 2001).]
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are trying to use an instancevariable, but since the object isn't finnished constructing it doesn't really exist yet. Remember that all classes ultimatly extends Object, so there is always a call to the superclass. All a this()-call does is delay the call to Objects constructor.
/Mike
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Payal,
Implicitly every class has its super class as java.lang.Object. Same is the case here.
When you try to instantiate class Test, the Constructor is called first and then the instance variables gets initialized.However calling this(a) means you are calling Constructor Test(int) when a is still not initialized, i.e the Object of Test is still not created and hence instance varaible a is still not initialized.
The above problem could be solved, if you modify the code to :


Hope this helps,
Sandeep
SCJP2, OCSD(Oracle JDeveloper), OCED(Oracle Internet Platform)
[This message has been edited by Desai Sandeep (edited July 28, 2001).]
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic