Atul Chandran

Greenhorn
+ Follow
since Oct 24, 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 Atul Chandran

I think the question Amit asked is quite clear . Since the reference is of type foo.Person the only setter method available will be

public void setName(String name)

The other setter method public void setEmpID(int empID) is not defined or declared in Person. So the only property that may be set is name.
System.out.println(null);//will result in a compiler error

The compiler is unable to decide which method to call println(char[]) or println(String). Or in the words of the compiler "reference to println is ambiguous".

But in this case the compiler cannot determine the value being printed. The actual method call (call to toString()) is deferred until runtime. The first call returns null and the JVM is unable to decide which println to call and hence it throws a NullPointerException.

I think this is the case.But I am not sure about it??




s = s + r;
The above line will produce a new String literal "abcnull" and s will be referring to this new object. The String object "abc" referred to by s previously will be eligible for garbage collection.

Note in the question it is given as "Before statement 4" and local variables become eligible for garbage collection only after statement 4.
String s2 = s1.replace('m','r');
The above is same as
String s2=new String("arit");
Which will create a new String object "arit" in the non String pool area of memory and s2 will be referring to that object.
Sorry my mistake ...you are right..I have editided my post...Didn't look at the code closely.
When x is passed to the method findOut(Integer y) the value contained in x is copied to y. The value contained in x is not the object itself but a value which can be used to locate the object.

Since x and y will contain same values they can both locate and access the object. We are only setting y to null but x still contains the value...or in other words a reference to the Integer object and hence it cannot be garbage collected.
[ November 10, 2004: Message edited by: Atul Chandran ]
5. argCopy[0] = args;

after this line argCopy[0] will be refering to the array of length 3 which is reffered to by arg.

before line 5
argcopy[0]-------->[null] [null] /*an array of length 2 whose elements are initialized to null.*/


after line 5.
argcopy[0]-------->["1"] ["2"] ["3"]//an array of length 3 .

[ November 10, 2004: Message edited by: Atul Chandran ]

[ November 10, 2004: Message edited by: Atul Chandran ]
[ November 10, 2004: Message edited by: Atul Chandran ]
In Runnable interface run() is only declared not defined.
int [][] x = new int[2][2];
Here x is a two dimensional array. x can hold 2 arrays of length 2 in the positions x[0] and x[1].

x[0] can hold an int array of length 2.
x[1] can hold an int array of length 2.
Every class extends Object class implicitly. But explicitly mentioning it does not result in an error. An analogy to instance variables will make it clear.

String a;//a will be assigned null by default.
String b=null;//is legal and null is assigned to b.
similarly
class A{} //A will extend Object by default
class B extends Object {} //legal and B extends Object class.
If dg is returned and is assigned to a two dimensional array in the method which called getIt() then the object will not be eligible for garbage collection since two references will be reffering to the object.
Nop they are character literals...

Hi Barry,
String a=new String("Hello");//will create two objects

one in the non pool area of memory and
one is added to the String pool.

My question is whether the String "Hello" will be added to the pool if already a "Hello" object is present in the pool.
Hi,
The following code will create two String objects
1. String r=new String("Hello");
One in the non pool area of memory and one in the String pool.

How many String objects will line 3. create? 1 or 2? And will the existence of "Hello" String in the pool make any difference?

2.String a="Hellp";
3.a=a.replace('p','o');

And will the existence of "Hello" String in the pool before line 1 make any difference?
Thanks in Advance,
Atul
It is just a snippet. And the absence of main method will never result in a compile time error it will only result in a runtime error. Line 15 will result in a compile time error because ob is not an array(It should have been ob=null) and I have no idea about line 16..
There is no guarantee for the order in which the threads will be executed. It depends on the scheduler.
[ October 31, 2004: Message edited by: Atul Chandran ]