Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract Method & Static Abstract Class, Methods

 
Kalyan Naveenan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now that i understood the concept abstract method can someone help me in understanding when and why is there a use for abstract method. Secondly i would like to know if there is a possibility of using an abstract static class in java so that even though instantiation is not allowed, is there a chance of accessing the methods and instance variables from another class ?
 
Keith Rainey
Ranch Hand
Posts: 66
Android Eclipse IDE IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would use an abstract class as the basis for other more specific subclasses. For instance, you might abstract the Vehicle class with subclasses Tricycle, Bicycle, Car


You can specify the common elements that all the types will have ( color, numberOfWheels, etc) , the things they must be able to do ( start , stop, accelerate, decelerate, etc). The abstract class will NOT specify *how* the subclasses will implement them. A tricycle will have a different number of wheels than a car and it will perform all the behaviors (methods) differently.
 
Keith Rainey
Ranch Hand
Posts: 66
Android Eclipse IDE IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One point of clarification: you can also have concrete methods in an abstract class. All subclasses will contain those members.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kalyan Naveenan wrote: Secondly i would like to know if there is a possibility of using an abstract static class in java so that even though instantiation is not allowed,

There is no abstract static classes in Java
 
Kalyan Naveenan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Keith Rainey and Mohamed Sanaulla for the explanation.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Sanaulla wrote:
Kalyan Naveenan wrote: Secondly i would like to know if there is a possibility of using an abstract static class in java so that even though instantiation is not allowed,

There is no abstract static classes in Java

There can be - static abstract nested classes. No top-level class can be static, no matter if the class is abstract or not.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic