Amit Chowdhary

Greenhorn
+ Follow
since Feb 10, 2001
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 Amit Chowdhary

Jyotsna,
That�s okay, I understood the concept very well. Thanks!!!
regards,
Amit
23 years ago
Thanks Jyotsna. That was great explanation. It'll help me a lot, as i always make mistakes in object reference.
23 years ago
Hi all
I'm executing this code and the result that i'm getting is different than what i was expecting. can some help me with this.
---------------
class ClassRef{

public static void main(String a[]){
Test2 t2 = new Test2();
Test1 t3 = t2;
System.out.println("t2.s: "+ t2.s);
System.out.println("t3.s: "+ t3.s);

t2.method();
t3.method();
}
}
class Test1{
String s ="test1";
void method(){
System.out.println("test1Method");
}
}
class Test2 extends Test1{
String s ="test2";
void method(){
System.out.println("test2Method");
}
}
--------------
o/p is:
t2.s: test2
t3.s: test1
test2Method
test2Method
-------
I was expecting:
t2.s: test2
t3.s: test2
test2Method
test2Method
-------
I'm still thinking that after this line of code
Test1 t3 = t2;
t3 refers to Test2 class instance and should give
t3.s value as "test2".
Thanks
23 years ago