Skip to content

Instantly share code, notes, and snippets.

@hasankucuk
Last active January 16, 2019 08:47
Show Gist options
  • Save hasankucuk/e3a68ad83345a8ee91cc3d4555e354c8 to your computer and use it in GitHub Desktop.
Save hasankucuk/e3a68ad83345a8ee91cc3d4555e354c8 to your computer and use it in GitHub Desktop.
Best Example of Abstract class in Android
I want to complete Hiren Partel Answer with an example.
Abstract method of abstract class must be Override in Derived class
Non abstract method of abstract class always call method of Super class
If abstract class Implements an Interface it is possible to not to Implement methods and let the finally driven class to Implement the Interface methods
for example GOD controls his creature on Earth by implementing this interface ( :D) :
public interface َAliveCreature{
void breath();
void eat();
void move();
void die();
}
And this is abstract class live that have one public method and one abstract method:
public abstract class MammalAbstract implements َAliveCreature{
public void feedBabyWithMilk(){
log.i(TAG,"baby was fed");
}
abstract void haveDream();
//this is an abstract method and had to implement in the consumer class
}
and this is finally driven class, human:
public class Human extends MammalAbstract {
@Override
void die() {
}
@Override
public void breath() {
}
@Override
public void eat() {
}
@Override
public void move() {
}
@Override
public void haveDream() {
}
}
as you can see human had to implement abstract method haveDream() and also implement abstactclass interface methods! so this is the power of an abstract class that can handle and add some method and pass rest Interface methods to consumer and very use-full for writing libraries.
https://stackoverflow.com/questions/34331284/best-example-of-abstract-class-in-android/34332420#34332420
http://hannesdorfmann.com/android/library-abstract-class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment