Java For Android Tutorial #20: Abstraction Basics

Code:

package com.example;
public class java {
    public static void main(String[] str) {
        Parent parent = new Parent();
    }
}
abstract class Parent{
    public void method1(){}
    public abstract void method2();
}
class Child extends Parent{
    @Override
    public void method2(){}

}
Abstractions provide coders with simple options. Abstraction is about going after ideas rather than
Rule#1: Abstract methods can't be declared in the non-abstract class.
 going into the implementation details. And there are certain rules you have to take care of:
Rule#2: You can't create an object of an abstract class. You have to use it by creating a subclass.
Rule#3: If you are creating a subclass of an abstract class, it is necessary to implement all the abstract methods of the parent abstract class.
Rule#4: An abstract class can have non-abstract methods.

Comments

Popular Posts