• 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

question on static members

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
class B{
static String s1 = "hello";
static void test(int k){return k;}
}

class A extends B{ }
My question is: Are the static members of class B inherited into class A?
Thanks for your reply,
Meghasyam.
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Meghasyam
Static variables are no different than non-static variables when it comes to inheritance.


My question is: Are the static members of class B inherited into class A?


Answer : Yes
[ June 14, 2003: Message edited by: Anupam Sinha ]
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no they are not a static member means that its shared among all objects meaning you acsses them from any static method for exsample the main method
without crating an object of that class
there is only one copy of those static members
and they are shared among all objects
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Adi
Well the answer I think is Yes. If you have any reason to support your answer I would like to know that. Sharing of a variable doesn't means that it's not inherited and I guess that my example above shows that static vars are inherited. Secondly

no they are not a static member means that its shared among all objects meaning you acsses them from any static method for exsample the main method
without crating an object of that class


Access from non-static methods is also allowed.
They can also be accessed by creating an instance of the object, though that's not recommended.
[ June 14, 2003: Message edited by: Anupam Sinha ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic