Abstract Class in java Program

Abstract class and methods is many time uses in java programs when we want to create indexing of our methods in some secure class.

Why Abstract class is secure?

– We can’t create an object of Abstract Class, so we have to inheritance abstract with sub class. So, all access of abstract classes is managed by sub class. We can’t directly access from main class.

Rules of Abstract Class

– Can’t create an object of abstract classes

– Must be inheritance

– abstract methods must be in abstract classes

– abstract methods only declare in abstract classes, must be override in sub class

 

 

Example on Abstract classes and methods

abstract class A

{

                abstract void methodA();             // Dec of method – Indexing

                void normalMethod()

                {

                                System.out.println(“Welcome in Normal Method”);

                }

}

class B extends A

{

                void methodA()

                {

                                System.out.println(“Welcome in Abstract Class’s Method”);

                }

}

class inh11

{

                public static void main(String args[])

                {

                                //            A obj = new A();               // Create an Error

 

                                B obj = new B();

                                obj.methodA();                                                // call to overide method

                                obj.normalMethod();                    // call to inheritance class method

                }

}

Output:

Welcome in Abstract Class’s Method

Welcome in Normal Method

 

Video available on YouTube.


[sbscrbr_form]

If you have any query on blog example, you can directly comment us or subscribe our website


Earn Money Online

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

472total visits,2visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

EmailEmail
PrintPrint