A constructor is a special method available under every class responsible for initializing variables of the class.The name of the constructor method will be the same as the class name and the method does not return a value.Every class requires a constructor for execution and if not present the class can't be executed so if the programmer did not define a constructor under his class then the compiler defines a constructor for the class while compiling.We can also define our own constructor in a class as follows:[ <modifiers>] name ([ <param definations>]){Statements}Class Condemoclass Condemo(){Console.writeline("constructor");}Void demo{Console.writeline("method");}static void main(){Condemo cd1=new Condemo();Condemo cd2=new Condemo();Condemo cd3=cd2;Cd1.demo();cd2.demo();cd3.demo();Console.readline();}}When we execute the above class the first statement under constructor condemo() will execute thrice and then all remaining operations are executed.The constructor are of two types
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: