1. First, we elicit the abstract, we used to write in a parent class and write a subclass of the time, to be subclass overrides the parent class method, then the parent class method body original content entity method in no meaning, because the method is performed after the subclasses override method overrides. All we want to parent class method body needs subclass overrides the method to remove, this time on the need to use the abstract keyword
public class Error { public static void main(String[] args) { B b=new B(); b.m(); } } class A { // attribute String name; // Method public void M1 () { System.out.println ( "method of the parent class overrides the method body code is meaningless" ); } } class B extends A{ public void m() { System.out.println ( "method is performed after the rewriting of the subclass" ); } }
After transformation
public class Error { public static void main(String[] args) { B b=new B(); b.m(); } } abstract class A {// abstract class can have an abstract method // attribute String name; // methods public abstract void m (); // change the abstract methods } class B extends A{ public void m() { System.out.println ( "method is performed after the rewriting of the subclass" ); } }
1. With the abstract method in a class, then the class will become abstract class