• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

How to create an abstract method that can be accessed through the class reference and not instance?

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

Imagine there is an abstract class called Vehicle, the class should have an undefined field or method for the number of wheels the vehicle is suppose to have! This class has sub-classes such as Car, Motorcycle and Truck that implement the number of wheels, however this number is exactly the same, it is shared, across all instances of the sub-classes, but not all classes, it's unique to but shared across all instances of a sub-class. This number of wheels, can also be accessed without the need for instantiation of any sub-class that extends the abstract class called Vehicle? Some say including both the static and the abstract modifier, however firstly you cannot have the abstract modifier on a field, and static means that something is shared across all sub-classes, not only instances, which is not object oriented. How can I do this?

Kind Regards,
Augustas
 
Marshal
Posts: 76884
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Calling a method abstract and static is a contradiction in terms. All abstract methods are implicitly not static.
 
Augustas Fiore
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, so how do I do this?

Kind Regards,
Augustas
 
Sheriff
Posts: 8542
615
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Augustas Fiore wrote:Okay, so how do I do this?

Please show us first what have you tried yourself?
 
Campbell Ritchie
Marshal
Posts: 76884
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hpw do you do the impossible?
 
They weren't very bright, but they were very, very big. Ad contrast:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic