469,645 Members | 1,424 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

plz explain this ?????

dmjpro
2,476 2GB
how can i explain this .........

class S1
{
static void Static()
{
System.out.println("Here i m ...");
}
}

class S2 extends S1
{
void test()
{
Static();
}
}

class StaticTest1
{
public static void main(String args[])
{
S2 s = new S2();
s.test();
}
}


i think u know the output ..... here i m

how can i explain thisss .... plz help

thnaxxxx
Mar 20 '07 #1
6 1201
sicarie
4,677 Expert Mod 4TB
Well, how would you explain it? What do you know is happening (hint, you already told us with the output)?
Mar 20 '07 #2
r035198x
13,262 8TB
how can i explain this .........

class S1
{
static void Static()
{
System.out.println("Here i m ...");
}
}

class S2 extends S1
{
void test()
{
Static();
}
}

class StaticTest1
{
public static void main(String args[])
{
S2 s = new S2();
s.test();
}
}

i think u know the output ..... here i m

how can i explain thisss .... plz help

thnaxxxx
Well, wouldn't you expect that output DJ? You did call the method called static which prints that message.
Mar 20 '07 #3
dmjpro
2,476 2GB
actually what i understood ..... that is

the static method never in herited so how the class S2 knows Static

and how the static method resolved by compiler and what compiler tells the JVM to do???????

plz clearify me in details ..... thanxxx
Mar 20 '07 #4
sicarie
4,677 Expert Mod 4TB
actually what i understood ..... that is

the static method never in herited so how the class S2 knows Static

and how the static method resolved by compiler and what compiler tells the JVM to do???????

plz clearify me in details ..... thanxxx
What does the call to instantiate S2 do? (What does it call?)
Mar 20 '07 #5
dmjpro
2,476 2GB
JVM call these function but JVM take decision according to compiler ???

as i previously i knew from this site ...... that the staic method resolved during compile time ... but here i stuck

i think as the S2 extends S1 then inside test() method the Static() calls internally converted into S1.Static()....

m i right ??????

plz help .....
Mar 20 '07 #6
sicarie
4,677 Expert Mod 4TB
i think as the S2 extends S1 then inside test() method the Static() calls internally converted into S1.Static()....
The call to instantiate S2 creates the Static() method which is inherited through the 'extends' keyword, and then is invoked in the StaticTest1.

I'm not too sure on the internals of this - I do not believe that an S1 object is created separately from S2 (as S2 extends, it is considered a member of the superclass Object, and then S1, and then S2 - technically every S2 is an S1...). I'm sure another expert on here could verify/disprove this...
Mar 20 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Bruce D | last post: by
14 posts views Thread by Ina Schmitz | last post: by
2 posts views Thread by Buck Nuggets | last post: by
2 posts views Thread by heming_g | last post: by
5 posts views Thread by kabotnet | last post: by
1 post views Thread by w.l.fischer | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.