• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to Determine Reference Type in the Following Case

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


Deepak
[ May 11, 2005: Message edited by: Mark Spritzler ]
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Ranch Hand
Posts: 817
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...?
 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone explain in more detail, why is the static method of P is getting called?
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
shetal bansal
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic