This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How to Determine Reference Type in the Following Case Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How to Determine Reference Type in the Following Case" Watch "How to Determine Reference Type in the Following Case" New topic
Author

How to Determine Reference Type in the Following Case

deepu Bhalotia
Ranch Hand

Joined: Apr 19, 2005
Posts: 39

what is reference type of the Object created in Line 1...


Deepak
[ May 11, 2005: Message edited by: Mark Spritzler ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

OK, so first lets format your code so that we can read it by using the CODE tags that get created when you click the CODE button under the Add Reply button.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

new q().printS1S2(); // 1


Nothing is created on this line, just a compile time error because you need to capitalize the "q".

Mark
[ May 11, 2005: Message edited by: Mark Spritzler ]
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
hi ya after capitalising Q it will compile

here no reference type is declared so no reference type will be created
the answer will be

P.printS1
Q. prints2

the tricky point here is that ... thought instance variable is of Q
but static method of p will be called if the call is made from that class irrespective of instance variable...

hey other ranchers..is i m rt...?


Thanks and Regards, Amit Taneja
soumya ravindranath
Ranch Hand

Joined: Jan 26, 2001
Posts: 300
Originally posted by amit taneja:

the tricky point here is that ... thought instance variable is of Q
but static method of p will be called if the call is made from that class irrespective of instance variable...


What exactly are you saying ?

( that, printS1S2() will call P.printS1() and Q.printS2() ? that's correct )
[ May 11, 2005: Message edited by: soumya ravindranath ]
shetal bansal
Ranch Hand

Joined: May 09, 2005
Posts: 63
Can anyone explain in more detail, why is the static method of P is getting called?
Kumar J
Ranch Hand

Joined: Feb 13, 2005
Posts: 35
static void printS2(){
System.out.println("p.PrintS1");
}
void printS2(){
System.out.println("P. printS2");
}


Can we have same method names printS2(non-static) and printS2(static) ?

[ May 12, 2005: Message edited by: Mr Kumar J ]

With Regards,<br />Kumar J
shetal bansal
Ranch Hand

Joined: May 09, 2005
Posts: 63
I think thats a typo error,
it is
_______________________________
static void printS1(){
System.out.println("p.PrintS1");
}
void printS2(){
System.out.println("P. printS2");
}
________________________________
else we will get a compilation error.
Deepu pls. confirm!!
 
 
subject: How to Determine Reference Type in the Following Case
 
Similar Threads
Question on inheritance from Dan's exam
static methods and NULL
anotherone from Dan's
overriding
Shadowing static methods