An abstract class can contain zero or more abstract methods. The abstract keyword must be used here.
For Example,
Points to Remember:
1.You can have instance variables and concrete methods.
2.You cannot create object to abstract class.
3.While you are extending the abstract class, all the abstract methods should be implemented in its sub class.
4.If the abstract method is not implemented in its sub class, then that sub class should also use abstract keyword.
For Example,
abstract class JavaHit { //abstract method abstract void test(int n, int m); } class First extends JavaHit { //Add two values void test(int j, int k) { int p = j+k; System.out.println(“Added value is ” + p ); } } class Second extends JavaHit { //Subtract two values void test(int j, int k) { int p = j-k; System.out.println(“Added value is ” + p ); } } class LastOne { public static void main(String args[]) { First first = new First(); Second second = new Second(); first.test(1,3); second.test(2,4); } }
Points to Remember:
1.You can have instance variables and concrete methods.
2.You cannot create object to abstract class.
3.While you are extending the abstract class, all the abstract methods should be implemented in its sub class.
4.If the abstract method is not implemented in its sub class, then that sub class should also use abstract keyword.
No comments:
Post a Comment