0% found this document useful (0 votes)
9 views9 pages

Abstraction in Java by Deepak Smart Programming Lyst9128

The document provides an overview of abstraction and data-hiding in Java, explaining concepts such as private access-modifiers, abstract classes, and methods. It outlines the differences between concrete and abstract methods and classes, emphasizing their characteristics and usage. Additionally, it includes interview questions related to these topics for further understanding and preparation.

Uploaded by

monikasatnami73
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views9 pages

Abstraction in Java by Deepak Smart Programming Lyst9128

The document provides an overview of abstraction and data-hiding in Java, explaining concepts such as private access-modifiers, abstract classes, and methods. It outlines the differences between concrete and abstract methods and classes, emphasizing their characteristics and usage. Additionally, it includes interview questions related to these topics for further understanding and preparation.

Uploaded by

monikasatnami73
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Smart Programming : Channel

An investment in Knowledge pays the best interest….

Abstraction in Java
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

=> Data-Hiding :-
-> Data-Hiding is the process of hiding the data
from outside users
-> It is achieved by private access-modifier
-> Example :
class Account
{

1
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

private int balance; //data hiding


//code---
}
-> To access or modify or update private
variables java provide some special methods i.e.
getter and setter methods
-> It is highly recomended to declare variables
(data members) as private

=> Abstraction :-
-> Abstraction is hiding the details (hiding the
implementation part) and just highlight the main
services
-> Real world example : Car (internal working of
breaks, gears etc are hidden from user), Bank
(internal working of credit/debit is hided form user

2
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

and only main component i.e. textfield and button is


shown) etc
-> It is achieved by abstract class & interfaces

------------------------------------------------------------

=> Abstract class :-


-> Abstract class are those which can contain
both concrete methods and abstract methods
-> Syntax :
abstract class Test

{
//concrete methods
void sum()
{
//coding
3
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

}
//abstract methods
abstract void show();
}

=> Abstract method :-


-> For example : Devils
-> 1. Abstract methods are those whose
implementation part is hided
2. Abstract methods are those which does not
have body or implementation part
3. Abstract methods are those which have only
declaration part, not implementation
-> Syntax :
abstract void sum();
-> To declare abstract methods we have to use
"abstract" keyword

4
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

=> Points to remember :-


1. If any class contains abstract methods then
that class should be declared as abstract class
2. If we declare any abstract class, then it can
contain both concrete methods as well as abstract
methods and it can contain only concrete methods
3. We cannot create an object of abstract class
or we cannot instantiate an abstract class but we
can declare reference for an abstract class
4. If any class inherits abstract class then it
should implement all the abstract methods or that
class should also be declared as abstract
5. Whenever we use abstraction concept we are
using method overriding concept also
6. Abstract class can have constructors
7. Abstract class can inherit concrete class
8. We can overload abstract methods

5
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

Interview Questions :-
1. What is difference between concrete methods and
abstract methods ?
-> Concrete Methods : which have both
declaration and implementation part
Abstract Methods : which have only
declaration part
-> Concrete Methods : we dont need to use any
keyword

Abstract Methods : we have to use "abstract"


keyword
-> Concrete Methods : provides less shareability
Abstract Methods : provides more shareability
-> Concrete Methods : can be provided in
concrete class and abstract class

6
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

Abstract Methods : can be provided only in


abstract class

2. What is difference between concrete class and


abstract class ?
-> Concrete Class : which can contain only
concrete methods
Abstract Class : which can contain both
concrete methods as well as abstract methods
-> Concrete Class : we can create an object of
concrete class
Abstract Class : we cannot create an object of
abstract class
-> Concrete Class : it does not require any
specified keyword
Abstract Class : it can be declared only by
using "abstract" keyword

7
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

Company Links & Contacts

Company Name: Smart Programming (+91 62838-30308)

Address : Chandigarh & Mohali (Punjab), India

Websites: https://www.smartprogramming.in/
https://courses.smartprogramming.in

Android App:
https://play.google.com/store/apps/details?id=com.sma
rtprogramming

YouTube Channel:
https://www.youtube.com/c/SmartProgramming

You might also like