Happy Diwali
happy diwali

Saturday, 12 April 2014

Abstract

Abstraction
Abstraction is a process of hiding the implementation details and showing only functionality to the user. Another way, it shows only important things to the user and hides the internal details.
Achieve Abstaction
There are two ways to achieve abstraction in java
1.   Abstract class (0 to 100%)
2.   Interface (100%)
Abstract class
A class that is declared as abstract is known as abstract class.It needs to be extended and its method implemented. It cannot be instantiated.
Example  :
abstract class A
{
// abstract methods
// some concrente methods
}
abstract method
A method that is declared as abstract and does not have implementation is known as abstract method.
abstract return_type <method_name>();//no braces{}
Example :
abstract void test();
abstract int method (inti) ….. etc
It should be used abstract keyword

Small points on abstract class :

Example:
abstract class F
{
Variables declaration possible
          static int i;
          int j;
A I;
Methods declaration can’t possible
          //void test();
          //static void test();
Methods implements possible
          static void test1()
          {
                             }
 int test2()
{
//Some stmts
Return 10;
}
Blocks
SIB
static
          {
                   System.out.println("hi static");
          }
IIB
          {
                   System.out.println("hi");
          }
Final Keyword can’t be used in abstract class
          /*abstract final A
          {
                  
          }*/
         
Void test9()
{
System.out.println(“over riding before”);
}

          abstract void tet2();
Abstrac method implementation not possible
          //abstract void test5()
          {
          }
Object Cration not possible by using new keyword
          //F f1=new F();
Constructer is possible in abstruct class
          F()
          {
                   System.out.println("F()");
          }
Inner Classes are possible in side abstract class
          class D
          {
                  
          }
private class R
{
          }
}
abstract class T extends F
{
          void test2()
          {
                  
          }
Overriding possible in abstract class
Void test9()
{
System.out.println(“over riding before”);
}


}

No comments:

Post a Comment

happy diwali
happy diwali