Abstract class is the class which can hold fully implemented methods and unimplemented methods. That’s the major difference between Interface vs Abstract class. Have a look on below section 1.0, which demonstrate template for Abstract class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
Section 1.0 package technical.jungle.com.abstractdemo; public abstract class TechnicalJungleAbstract { void showValue(){ System.out.println("www.technicaljungle.com \t Value = " + someComplexCalculation()); } private int someComplexCalculation(){ /*This method is hidden from classes, who all are going to inherit this abstract class.*/ return (int) (Math.random()*10) * setValue(); } public abstract int setValue(); } Section 1.1 package technical.jungle.com.abstractdemo; public class JungleFirst extends TechnicalJungleAbstract{ public static void main(String[] args) { JungleFirst first = new JungleFirst(); first.showValue(); } @Override public int setValue() { return 1; } } Output : www.technicaljungle.com Value = 5 ( this value will be random) |
Some key points about above demo: abstract keyword is used. ……………