Abstraction in Java





  • The mechanism of representing only essential features without showing the unwanted background details is called abstraction.

  • Data abstraction refers to, providing only essential information to the outside world and hiding their background details, i.e., to represent the needed information in program without presenting the details.

Let's talk about real life example:
Abstraction shows only important things to the user and hides the internal details for example when you ride a bike, you only know about how to ride bike but do not know about how it work ? and also you do not know internal functionality of bike.
When you accelerate bike speed get fast, when push break it gets stop, you only know that these things have these functionality but do not know how they perform .

In Java program if we implement class with private and public members then it is an example of data abstraction.

Example :

import java.util.Scanner;
class Sum
{ 
//hidden data from outside world
 private int x, y, z;
 public void add()
 {
  System.out.print("Enter two numbers:");
  Scanner sc  = new Scanner(System.in);
  x = sc.nextInt();
  y = sc.nextInt();
  z = x+y;
  System.out.print("Sum :"+z);
  }
public static void main(String []arg)
 {  
  Sum sm = new Sum();
  sm.add();
 }
}                    
OUTPUT:
Enter two numbers:5
3
Sum : 8

Next topic is inheritance




 

Training For College Campus

We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.

Please mail your requirement at info@prowessapps.in


Projects For Students

Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.

Students can mail requirement at info@prowessapps.in



CONTACT DETAILS

info@prowessapps.in
(8AM to 10PM):

+91-9026070669 , +91-9451396824

© 2016, prowessapps.in, All rights reserved