Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract class - Whetehere sub class should implement all the abstract methods of base class ?

 
kri shan
Ranch Hand
Posts: 1462
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public abstract class Vehicle {

abstract int total();

}


public class Car extends Vehicle {

}


Is it mandatory to implement abstract method total in the sub class Car?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64712
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. But if you don't, Car must also be abstract.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In other words, if the class is not abstract then yes. After all, a non-abstract class can have no abstract methods, even not inherited from an abstract super class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic