Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (anonymous):

What is difference between abstract class and interface?

OpenStudy (anonymous):

An interface is an empty shell, there are only the signatures (name / params / return type) of the methods. The methods do not contain anything. The interface can't do anything. It's just a pattern.

OpenStudy (anonymous):

Abstract classes, unlike interfaces, are classes. There are more expensive to use because there is a lookup to do when you inherit from them. Abstract classes look a lot like interfaces, but they have something more : you can define a behavior for them. It's more about a guy saying "these classes should look like that, and they got that in common, so fill in the blanks!".

OpenStudy (anonymous):

interface example:

OpenStudy (anonymous):

// I say all motor vehicles should look like that : interface MotorVehicle { void run(); int getFuel(); } // my team mate complies and write vehicle looking that way class Car implements MotorVehicle { int fuel; void run() { print("Wrroooooooom"); } int getFuel() { return this.fuel; } }

OpenStudy (anonymous):

abstract example:

OpenStudy (anonymous):

// I say all motor vehicles should look like that : abstract class MotorVehicle { int fuel; // they ALL have fuel, so why let others implement that ? // let's make it for everybody int getFuel() { return this.fuel; } // that can be very different, force them to provide their // implementation abstract void run(); } // my team mate complies and write vehicle looking that way class Car extends MotorVehicle { void run() { print("Wrroooooooom"); } }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!