• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Augustas Fiore
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Okay, so how do I do this?

Kind Regards,
Augustas
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • 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: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hpw do you do the impossible?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!