A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Certification
»
Programmer Certification (SCJP/OCPJP)
Author
How Many Objects Are Created?
Gowher Naik
Ranch Hand
Joined: Feb 07, 2005
Posts: 643
posted
Jul 29, 2006 01:31:00
0
public class Test14{ static String s ="Instance"; public static void main(String a[]){ Test14 t = new Test14(); s = "New Instance"; String s = "Local"; method(Test14.s); System.out.println(s); System.out.println(Test14.s); } public static void method(String s){ s+="Add"; System.out.println(s); } }
How many objects are created in above piece of code
According to me there are 5 objects created as follows
Ref Objects ------ ---------- "Instance" s--> "New Instance" s--> "Local" //(inside main) "Add" //(inside method named method) s--> "New Instance Add" //(inside method named method)
Thanks
Aum Tao
Ranch Hand
Joined: Feb 14, 2006
Posts: 210
posted
Jul 29, 2006 01:37:00
0
How many objects are created in the above code?
I think, you forgot t in Test14 t = new Test14();
[ July 29, 2006: Message edited by: Aum Tao ]
SCJP 1.4 85%
I agree. Here's the link:
http://aspose.com/file-tools
subject: How Many Objects Are Created?
Similar Threads
Please explain me answer. (static)
code
Javabeat mock 2, question 14
can anyone explain this
String variables in static method
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter