You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
abstractclassRBI{ //1.abstract class is a class in which few methods are given and few are not given..
2
+
publicfinalvoidsetFarmingRate(){ //2.this method is recommended and the rate for this method is fixed for all classes(banks)..
3
+
System.out.println("RBI farnming rate is 3%");
4
+
}
5
+
publicabstractvoidsetBusinessRate(); //3.these methods are compulsary and rate can be according to different classes..
6
+
publicabstractvoidsetHomeRate(); //4.not given methods.
7
+
}
8
+
9
+
classSBIextendsRBI{ //5.class that will extends abstract class will responsible to override all the abstract method of its superclass.....if it fails to do so then this derived class will also have to be declared abstract.
10
+
publicvoidsetBusinessRate(){
11
+
System.out.println("sbi busuiness rate is 10%");
12
+
} publicvoidsetHomeRate(){
13
+
System.out.println("sbi home rate is 6.5%");
14
+
}
15
+
}
16
+
17
+
classPNBextendsRBI{ //6.same as 5
18
+
publicvoidsetBusinessRate(){
19
+
System.out.println("pnb busuiness rate is 11%");
20
+
} publicvoidsetHomeRate(){
21
+
System.out.println("pnb home rate is 6%");
22
+
}}
23
+
6+9
24
+
25
+
classAbstractDemo{
26
+
publicstaticvoidmain(Stringar[]){
27
+
RBIrbi; //object of abstract class cannot be created but its reference can be created..
28
+
SBIsbi=newSBI();
29
+
PNBpnb=newPNB();
30
+
System.out.println("pointing to sbi");
31
+
rbi=sbi; //reference of sbi can be stored in rbi....
32
+
rbi.setBusinessRate();
33
+
rbi.setHomeRate();
34
+
rbi.setFarmingRate();
35
+
System.out.println("pointing to pnb");
36
+
rbi=pnb; //refernce of pnb can be stored in pnb......
/*Anonymous Inner Class: a class has no name is known as anonymous inner class.it should be use if u have to override the method of class or interface ..*/
0 commit comments