Java | Abstract Classes & Methods :


             ~~ CORE-JAVA ~~


     1.1 Java Intorduction
     1.2 Java history
     1.3 Java features
     1.4 Diff b/w Java & C++
     1.5 Java Variables
     1.6 Java Data Types
     1.7 Typecasting
     1.8 Arrays

 2. OOPS

     2.1 Introduction
     2.2 Class
     2.3 Object
     2.4 Static Keywords
     2.5 Constructors
     2.6 This KeyWord


     3.1 Inheritance (IS-A) 
     3.2 Aggregation (HAS-A)


     4.1 Polymorphism & Its Type
     4.2 Method Overloading
     4.3 Method Overriding
     4.4 Super Keyword
     4.5 Final Keyword
     4.6 Dynamic Binding


     5.1 Abstract Classes & Methods
     5.2 Interfaces
     5.3 Abstract vs Interface


     6.1 Encapsulation


     7.1 String
     7.2 String Buffer
     7.3 String Tokenizer


     8.1 Predefined packages
     8.2 Userdefined Packages
     8.3 Access Specifiers


     9.1 Introduction
     9.2 Pre Defined Exceptions
     9.3 Try-Catch-Finally
     9.4 Throws, throw
     9.5 User Defined Exception


     10.1 Introduction
     10.2 Thread Creations
     10.3 Thread Life Cycle
     10.4 Life Cycle Methods
     10.5 Synchronization
     10.6 Wait() notify() notify all()


     11.1 Introduction
     11.2 Wrapper Classes


     12.1 Introduction
     12.2 List interface
     12.3 Set interface                                 12.4 Map interface                           


     13.1 Introduction
     13.2 Member inner class
     13.3 Static inner class
     13.4 Local inner class
     13.5 Anonymous inner class

 14. CoreJava Interview Questions

Abstraction :

  • As we know there are multiple features of OOPS, one of them is Abstraction.
  • Abstraction means “Hiding the internal implementation details and only showing the set of services what we are offering. “
    • Best example of Abstraction is “Bank ATM Machine”. Here Bank people are showing set of Services ( Balance check, Withdraw, Change Pin, etc ) what they are offering without highlighting internal implementations. This is nothing but Abstraction only.
  • The main advantage of Abstraction is :
    • We can achieve better security, because no one is allow to know our internal implementation.
    • Without effecting Outside person, we can change our internal implementation. So we can say that enhancement will be very easy.
  • We can achieve Abstraction, in Java using :
    • Abstract Class
    • Interface

Abstract Modifier :

  • In Java, we have lots of Modifiers, one of them is Abstract.
  • Abstract is a Modifier which is applicable only for Classes and Methods but not for Variables.

Abstract Class :

  • A Class which is declared with Abstract keyword, is nothing but Abstract Class only.
  • Instantiation of Abstract Class is not possible, in other word we can say it is not possible to create an Object of abstract class.
  • Abstract Class can contains Abstract and Non-abstract both methods.
  • If a Class contains at least one Abstract Method then compulsory that class should be declare as Abstract Class, otherwise we will get Compile Time error ( Because implementation of that method is not there, so we can’t create object for that class).
  • We can say Abstract Class can contains zero number of Abstract Method.
  • Abstract Class can have constructor and static methods also.
  • Final method is also possible for Abstract Class.
  • If we are extending an abstract class that has an abstract method, then we must either provide the implementation of the method or make this class abstract.

Syntax :

abstract class Demo {


Abstract Methods :

  • Method which is declared with Abstract keyword, is nothing but Abstract Method only.
  • Abstract Method means, such type of method which does not have implementation, only declaration will be there. In other word, we can say Suppose we don’t know about implementation but still we can declare that method with Abstract keyword as below.
    • abstract void getDetails();
  • Here Child classes will be responsible to provide implementation for Parent class Abstract methods.


Example of Abstract Class with Abstract Methods :

Help Others, Please Share