Skip to Content

   

The constructor method is a instance method that is automatically called when the class object is created.class_constructor is a static method which is automatically called exactly once before the class is first accessed.

class_constructor is defined with CLASS-METHODS and constructor is defined with METHODS.

 

Main_Defn.PNG 

If class is inherited from another class,only superclass can have constructor method.Sub class can not have constructor method.

If class is inherited from another class,superclass as well as subclass can have class_constructor method defined.

 

Sub_Defn.PNG 

Implementation of main class methods.

 

Main_Impl.PNG 

Implementation of sub class methods:

Sub_Impl.PNG 

Create objects and call methods. 

Main_Prog.PNG 

Output:

Output.PNG

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply