Thursday, November 2, 2017

What is Abstract Class ?

  • Abstract is a keyword that is use with class and method. In abstract class we can define both abstract and concrete method.
  • If a class contains any abstract method then class must be abstract.
  • If a class contains any abstract method then we have to implement it in the subclass.
  • Object of abstract class can't be created.
  • To create the object of abstract class, programmer should make use of concrete class. A class which provides implementation to all the abstract method which are present inside abstract class with the help of extends keyword is known as concrete class.

                     

 Example:

             public abstract class I20
          {
               abstract void Wheels();
               abstract void Sunroof();
          }    
            public class Asta extends I20{
            void Wheels()
        {
           System.out.println("Wheels: Alloyed wheels" );
        }
          void Sunroof()
       {
           System.out.prinln("SunRoof: Not Available");
       }
   }
          public class Showroom
     {
          public static void main (String args[]){
          I20 i = new Asta();
          i.Wheels();
          i.SunRoof();
    }
}





No comments:

Post a Comment