Prithwish Paul Chowdhury

Greenhorn
+ Follow
since May 16, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Prithwish Paul Chowdhury

I am planning for starting SCBCD exam preparation and wondering where may I get some resources about it? It is highly appreciated If I get informed about book [its Head First ejb and other] and mock exams sources for SCBCD.

Thanks

Prithwish
19 years ago
Hello every one,

I have just passed SCJP1.4 with 85%. I want to convey my gratitude to javaranch for such a nice educative environment for acheivement. Special thanks to Kathey & Bates for such a nice and comprehendable book for scjp

Time limit was not a problem and review questions on 2nd and 3 rd time basis is essential.

Thanks you folks for all the pointers and looking forward to get into EJB exam.
Regards

Prithwish Paul Chowdhury
19 years ago
Hi,

I have put some efforts to elaborate why the output came as you descibed.
If any constructor gets called the followings steps are followed:

STEP A * Set fields to default initial values (0, false, null)
STEP B * Call the constructor for the object (but don't execute the body of the constructor yet)
STEP C * Invoke the superclass's constructor
STEP D * Initialize fields using initializers and initialization blocks
STEP E * Execute the body of the constructor



Basically ,The instance variables are initialized before the execution of the body of constructor


- The analysis for two lines in main are listed as follows:

Mobile n = new Mobile();

calls Mobile() constructor

Set fields of instance variables of class "Mobile" to defaults (0, false, null);
So Mobile classes String device instance variables gets the value as : device = null

Call the constructor for the object

The first line implicitly calls to super()

Phone() constructor gets called,

-Set fields of instance variables of class Phone to defaults (0, false, null)
-calls the constructor for the object
-initilizes Phone classe's instance variables:=> String device = "Phone.device";
-Calls ALREWADY OVERIDDEN version of showDevice()
-It SUPPOSE To PRINT "Mobile.showDevice,"+Mobile instance variable "device" => "Mobile.showDevice,null"


The second line calls showDevice() which calls OVERIDDEN version of showDevice() and prints
"Mobile.showDevice,Mobile.device"


n.showDevice();
Here the instance of Mobile : n calls the method showDevice() and prints
"Mobile.showDevice,Mobile.device"


One may verify the concepts described above by changes at @(A), @(B) @(C):
The output is listed at the end of the code.



Output

device phone->Phone.device [Changes in @(A)]
Mobile.showDevice,null
device Mobile phone Mobile.device[Changes in @(B)]
device phone->Phone.device[Changes in @(C)]
Mobile.showDevice,Mobile.device
Mobile.showDevice,Mobile.device

Please feel free to reiterate any of the points missed in this regards.

Thanks
Prithwish