Results 1 to 6 of 6
- 09-24-2010, 02:18 PM #1
Order of EXECUTION followed by JVM!
I didn't understoOD the order of execution followed by JVM!! :confused:Can any explain to me. Thanx in advance.Java Code:class Main { static String throwMeThat(String myString) { System.out.println(myString); return myString; } public static void main(String[] args) { new Third(); } } class First { String var1inFirst = Main.throwMeThat("**I am var1inFirst**"); String var2inFirst = Main.throwMeThat("**I am var2inFirst**"); public First() { Main.throwMeThat("**I am the constructor in class First**"); } } class Second extends First { String var1inSecond = Main.throwMeThat("**I am var1inSecond**"); String var2inSecond; public Second() { Main.throwMeThat("**I am the constructor in class Second**"); } } class Third extends Second { String var1inThird; { var1inThird = Main.throwMeThat("**I am var1inThird**"); } String var2inThird; String var3inThird = Main.throwMeThat("**I am var3inThird**"); public Third() { Main.throwMeThat("**I am the constructor in class Third**"); var2inThird = Main.throwMeThat("**I am var2inThird**"); var2inSecond = Main.throwMeThat("**I am var2inSecond**"); } }“Give somebody a fish and they eat for a day.Teach somebody to fish they eat for life!”
- 09-24-2010, 02:22 PM #2
I mean when "new Third()" statement is executed.. I always assumed that the constructor Third() is called. But here assumptions are contradicted.. Plz help..
“Give somebody a fish and they eat for a day.Teach somebody to fish they eat for life!”
- 09-24-2010, 03:03 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,457
- Rep Power
- 16
What about the order don't you understand?
What do you get as an output, and what did you expect as an output?
- 09-24-2010, 06:47 PM #4
Actually I read in the Sun tutorials that when you call the constructor of the subclass the no-arguement constructor of the superclass is called automatically...
Now accordingly the output I expected was::
**I am var1inThird**
**I am var3inThird**
**I am the constructor in class First**
**I am the constructor in class Second**
**I am the constructor in class Third**
**I am var2inThird**
**I am var2inSecond**
all I want to know is that "when a subclass's constructor is called where the control of execution is transferred??"“Give somebody a fish and they eat for a day.Teach somebody to fish they eat for life!”
- 09-24-2010, 07:11 PM #5
Do the print outs from the constructors show that?where the control of execution is transferred
- 09-24-2010, 09:18 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,398
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
thread execution one after another
By turanan in forum New To JavaReplies: 16Last Post: 05-08-2012, 12:11 PM -
Help in execution of a Timer
By Alice.B in forum Threads and SynchronizationReplies: 1Last Post: 05-27-2010, 06:36 AM -
.BAT execution error
By hunterbdb in forum Advanced JavaReplies: 5Last Post: 02-23-2009, 05:41 AM -
JAR execution
By patoh in forum New To JavaReplies: 2Last Post: 11-26-2008, 09:09 AM -
Execution cut
By Eric in forum Advanced JavaReplies: 1Last Post: 06-27-2007, 03:52 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks