1
abstract class Bank{    
  abstract int getRateOfInterest();    
}    

class SBI extends Bank{    
  int getRateOfInterest(){return 7;}    
} 

class PNB extends Bank{    
  int getRateOfInterest(){return 8;}    
}    

class TestBank{    
  public static void main(String args[]){    
    Bank b;  
    b=new SBI();  
    System.out.println("Rate of Interest is: "+b.getRateOfInterest()+" %");    
    b=new PNB();  
    System.out.println("Rate of Interest is: "+b.getRateOfInterest()+" %");    
  }
}    

So what I read in the books and online is: "Abstraction is a process of hiding the implementation details and showing only functionality to the user."

So my question is, If I write implementation in Bank class, will it not be hidden?, can user see that implementation?

What is the actual mean of 'hiding' here?

Andy Turner
  • 137,514
  • 11
  • 162
  • 243
Arun Raaj
  • 1,762
  • 1
  • 21
  • 20
  • You should learn to indent your code, it makes it much easier for you and others to read. – Andy Turner Jan 18 '17 at 21:58
  • i apologize, andy – Arun Raaj Jan 18 '17 at 22:03
  • 1
    Based on your simple example, yes, if some other part of your program is handed some instance of `Bank` it won't care how `getRateOfInterest` is actually calculated, only that `Bank` provides the means to get it. For example, `SBI` could have additional functionality attached to it, but because the other parts of your program are only dealing with `Bank`, they won't know about, thus the functionality is hidden from them – MadProgrammer Jan 18 '17 at 22:03
  • `abstract` is the opposite of `concrete`. i.e. "In the abstract, you can perform that action" versus "if you perform this action here is exactly what will happen" – ControlAltDel Jan 18 '17 at 22:08

1 Answers1

-1

Don't confuse abstraction with obfuscation. Abstraction helps developer to focus on the interface rather than implementation, but it does not mean implementation details should not be reachable.

In your case, developer may focus on the class Bank and don't think about child classes SBI and PNB. Details of the implementation will be hidden from the user, but not in a sense that user can not find them if he/she wants.

Alexander
  • 753
  • 2
  • 10
  • 25
  • This is a comment, not an answer. Do not abuse the system by posting comments as answers before you have the required rep. Doing so will attract downvotes and delay achieving the necessary rep. – Jim Garrison Jan 18 '17 at 22:59