• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Marcus Green mock exam3 q44

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If static variables can be changed using class name & ref. var(usually not used) why cann't Static methods be invoked with ref.variable
Throw some light on this
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried out this piece of code which shows that both static variables and methods can be accessed by object references.
maybe the ques is wrong .
hope this helps
public class Xxx
{
static int i = 8;
static{System.out.println("at load time i is " + i);}
static void amethod(){
System.out.println("in static amethod()");
}
public static void main(String args[])
{
Xxx x = new Xxx();
x.i = 9;
System.out.println("refered by ref var i is " + x.i);
x.amethod(); // accessing amethod()
}

}
bye
Arijit
 
sankar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks arjit,
I was confused after taking that exam.Now i got my confidence.
this week i am taking exam & i need to maintain conf.& tempo.
Thanks for ur reply
sankar
 
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic