00:00
H02_a.png
/* 2. m/t w/o body , must declare abs. */ public class H02 { void start(); } //missing method body, or declare abstract void start();
/* 3. m/t w/o body with abs keyword. */ public class H02 { abstract void start(); } // H02 is not abstract and does not override abstract method start() in H02
/* 4. both cls. and its m/t are abs. : WORKS FINE */ abstract public class H02 { abstract void start(); }
/* 5. i/h pt abs. m/t w/o creating its body. */ abstract public class H02 { abstract void start(); } class car extends H02 { } // car is not abstract and does not override abstract method start() in H02
/* 6. i/h pt abs. m/t and create its body. */ abstract public class H02 { abstract void start(); } class car extends H02 { void start(){ System.out.println("starts with key"); } } class scoters extends H02 { void start(){ System.out.println("starts with kick"); } public static void main(String[] args) { } }
/* 7. make abs class obj in main m/t. */ abstract public class H02 { abstract void start(); } class car extends H02 { void start(){ System.out.println("starts with key"); } } class scoters extends H02 { void start(){ System.out.println("starts with kick"); } public static void main(String[] args) { H02 t = new H02(); } } // H02 is abstract; cannot be instantiated
/* 8. make obj. of cld cls and then use abs m/t. */ abstract public class H02 { abstract void start(); } class car extends H02 {//1 void start(){ System.out.println("starts with key"); } } class scoters extends H02 {//2 void start(){ System.out.println("starts with kick"); } public static void main(String[] args) { car c1 = new car();//1 c1.start(); scoters s1 = new scoters();//2 s1.start(); } } // starts with key // starts with kick
Home PREVIOUS NEXT