Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
Call to function inside construction?
raja kanak
Ranch Hand
Posts: 135
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I got this question from
www.jchq.net
public class BettyAck { public static void main(String argv[]){ BettyAck b =new BettyAck(); } public BettyAck() { Integer x = new Integer(10); findOut(x); Integer y = new Integer(99); Integer z = y; z = null; findOut(y); //here } public void findOut(Integer y){ y = null; } }
It compiles and run. I read that inside constructor, we can call only this and super then how come findOut(y) call works?
If my understanding is wrong, please correct. Thanks for any help.
rajakvk
live
S Vilish
Ranch Hand
Posts: 39
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I read that inside constructor, we can call only this and super
We can call any other method of the class inside the constructor.
Vilish
Burkhard Hassel
Ranch Hand
Posts: 1274
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi raja,
it is true that
in the first line
of the constructor, we can only this or super.
Remember however, that if you don't put a call to this or super, the compiler provides an invisible call to super:
public class BettyAck { public static void main(String argv[]) { BettyAck b = new BettyAck(); } public BettyAck() { [B]super(); // invisible first line[/B] Integer x = new Integer(10); // not really the first line findOut(x); Integer y = new Integer(99); Integer z = y; z = null; findOut(y); // here (something else unrelated to question) } public void findOut(Integer y) { y = null; } }
Yours,
Bu.
[ February 17, 2007: Message edited by: Burkhard Hassel ]
all events occur in real time
raja kanak
Ranch Hand
Posts: 135
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thanks a lot for your efforts.
live
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
GC
which objects are eligible for Garbage Collection?
confused............
can anyone explain this?
Garbage Collection
More...