• 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

Why Abstract and Static can't be applied together?

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have one small query regarding Abstract and Static.

Why both abstract and static class is not possible?

I know the reason for final and static, why the can't go hand in hand.

but,don't know such reason for static and abstract.

The same query I have for abstract and static methods also.

Please help me in resolving this query.
Thanks in Advance.

Manoj
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will explain in terms of methods, please relate it to classes the same way ...
abstract means theoretical and it means that any method declared abstract has to be defined again by the extending class. hence, if there is a class called SuperClass and it has a abstract method called func(), then if this class is extended by class A and also by class B, so we can have different implementstions for the method SuperClass.func() based upon the class we chose (A or B).
In case the method is marked static, then it means that that class SuperClass has only one copy of it and which is perfectly known to it( or defined properly). if you mark it abstract then the subclass "has to compulsarily" have a different implementation of func() from the superclass.
this is against the whole point over which static was created....
got it ?
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
abstract methods has to be defined in sub classes where as static methods will have only one copy i.e in super class where is has declared and defined . you can not define static methods inside a sub class unless if it is a private method.

Static means you will only one copy for all sub classes, you can access it directly through classname.methodname();
[ April 29, 2008: Message edited by: winay Kumar ]
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

does it work with instencs variables with same way

means if a SuperClass has a static instence variable and it is extended by a DriveClass that also has a same instance variable as in SuperClass but without static.
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it can be done.
reply
    Bookmark Topic Watch Topic
  • New Topic