Bindesh Vijayan

Ranch Hand
+ Follow
since Aug 21, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Bindesh Vijayan

I want to add to this disucssion that non-static inner class can inherit static members if needed.
Thanks
Jason,
That helped,wonderful example.
Thanks.
23 years ago
Jordi,
The reason why A is not correct is bcoz,
it is not necessary that if an object is not being referenced then only it will be garbage collected.There are times when the reference of the object is still being held by some reference variable and yet it becomes eligible for GC.This is the case when the reference becomes dead or is no more active.Here u need not put an explicit null into make it eligible for GC.The GC will itself come to find whether it is active or has become dead.An example will clear this:

class Aclass {
protected void finalize()throws Throwable {
System.out.println("Aclass.finalize()");
}
}
class Bclass {
Aclass a1=new Aclass();//reference as a member of class
protected void finalize()throws Throwable{
System.out.println("Bclass.finalize()");
}
}
public class ABclassDemo {
public static void main(String[]arg ){
Bclass b1=new Bclass();
b1=null;

//as soon as you put null Aclass reference in Bclass becomes dead
//hence eligible for GC
//so it is not necessary objects with no reference will alone be eligible for GC
//objects with reference could also be GC'd if reference becomes dead

System.gc();
}
}

Now if u consider C statement,in its own context it is right,but only when all the references to that object is either set to null or becomes dead.
THANKS
umm.. seems like everyone is after interfaces.Harjeetji you should read this thread
click here
Thanks

[This message has been edited by Bindesh Vijayan (edited September 10, 2001).]
23 years ago
Leena do believe what Jose says, there is one new string created when a+b is done.
c=a+b;
here a+b returns a new String whoose reference is stored in c,thus we have 2 strings object created.
But even if a+b were left unreferenced as in our case System.out.println(a + b);
then too we have new string created.And I here completely agree with Jose.
But i did found out a new thing which i was referring in my previous post.So that is only the doubt existing.
Thanks.
[This message has been edited by Bindesh Vijayan (edited September 10, 2001).]

Jose,
Look at this line in bytecode
19 new #7 class java.lang.StringBuffer
Don't you think a new StringBuffer object is created.This means that in the original program of Leena at line no. 5 we have two objects for garbage collection:
1) given by toString()
2)implicit StringBuffer()
This is elegible for Gc bcoz as soon as the println statement is over it is no more referenced by any active links.
Similar is the case at line no.8
Your comments(witness) please
THANKS.
Jordan be clear with one point that overloading has nothing to do with access modifiers(public ,protected,private,default) or return types.All worth is the arguments and the sequence of the same.
THANKS.
I am sorry Swati I was wrong there.You know it happens sometime .Actually I was wrong here

This means to say that if you havae a return statement in between the function then after reading that return statement it will return from the function without executing the other statements below the line.


This statement is true regarding C but not in Java.Iam sorry again.I was too quick.
But Iam cent percent correct with my logic behind the error.
As too you real question,
WHat's the ponit in having return statemnt

I'll try to find an answer for it or may be some one will answer it, before I do.
That's all OK.But I need you to tell me whether I was wrong with my answers.Since now you have created doubt in my mind.
THANKS.
This is what it means:


package p1;
public class A(){
A(){}//default constr. with default access
/*public member */
public static void prt(){
System.out.println("A.prt()");
}
}

outside package p1

import p1;
public class SomeClass{
public static void main(String[] arg){
{
//A a1=new A();//cannot instantiate since constructor of A()has default acces
A.prt();//no problem here, you can refer its public members
}
}


THANKS
[This message has been edited by Bindesh Vijayan (edited September 09, 2001).]
Swati I think you mistook the error.What I think, the problem is not bcoz you have return a statement, but the problem is that you are trying to print the value returned from the method in println statement.
System.out.println takes a valid arg but since your method is not returning any thing,bcoz simply saying return in any function means to return from that position.This means to say that if you havae a return statement in between the function then after reading that return statement it will return from the function without executing the other statements below the line.
This is the use of return .Here is a small example

public void ret()
{
if(true)
{
System.out.println("Swati1");
return;
}
else
{
System.out.println("Swati2");//this will not be printed
}
}

Thanks.
[This message has been edited by Bindesh Vijayan (edited September 09, 2001).]
This is what I said
Manju.
Thanks Jose.
I understood the internal working.But I want you to tell me was i wrong with my answer.I can't get the reason bcoz to me whent a stringbuffer obj is created that too becomes eligible for GC after print statement.Please clear it.
THANKS
[This message has been edited by Bindesh Vijayan (edited September 08, 2001).]