wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Pelase Help me out imme.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Pelase Help me out imme...." Watch "Pelase Help me out imme...." New topic
Author

Pelase Help me out imme....

deepu Bhalotia
Ranch Hand

Joined: Apr 19, 2005
Posts: 39
class A {String s1 = "A";}
class B extends A {String s1 = "B";}
class C extends B {String s1 = "C";}
class D {
static void m1(A x) {System.out.print(x.s1);}
static void m1(B x) {System.out.print(x.s1);}
static void m1(C x) {System.out.print(x.s1);}
public static void main(String[] args) {
A a; B b; C c; a = b = c = new C();
m1(a); //1
m1(b); //2
m1(c); //3
}}


// Hi Guys,
Can you pleas explain me .... in line 1,2 and 3 which method will be called.

Thanks,
Deepak
Rohan Kayan
Ranch Hand

Joined: Sep 17, 2004
Posts: 123
class A {String s1 = "A";}
class B extends A {String s1 = "B";}
class C extends B {String s1 = "C";}
class D {
static void m1(A x) {System.out.print(x.s1);}
static void m1(B x) {System.out.print(x.s1);}
static void m1(C x) {System.out.print(x.s1);}
public static void main(String[] args) {
A a; B b; C c; a = b = c = new C();
m1(a); //1
m1(b); //2
m1(c); //3
}}




The output will be A B C , as it is a compile time binding which depends on the type of reference , not on the actual object .


SCWCD 1.4, SCJP 1.4
deepu Bhalotia
Ranch Hand

Joined: Apr 19, 2005
Posts: 39
I know the Output...
My Question is ...

which overloaded method will be called by
m1(a)....m1(b), m1(c)..statements...


Thanks
Deepak
Ramesh Ch
Greenhorn

Joined: Dec 26, 2000
Posts: 25
Hi,

m1(a) called the m1(A x)
m1(b) called the m1(B x)

m1(c) called the m1(C x).

Thanks
Soni Prasad
Ranch Hand

Joined: Mar 09, 2005
Posts: 97


line no. 1 -> m1(A x) line no. 4
line no. 2 -> m1(B x) line no. 5
line no. 3 -> m1(C x) line no. 6


SCJP 1.4, SCBCD 1.3
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pelase Help me out imme....