1. + 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y
S O L I D I T Y
C O N S T R U C T O R
2. + 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y
confidential @Tutorials Diary | www.tutorialsdiary.com
What it is ?
What is constructor
in solidity ?
3. + 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y
confidential @Tutorials Diary | www.tutorialsdiary.com
Constructor
A constructor is an instance method that usually has the same name as the contract or use
constructor keyword, and can be used to set the values of the variable of contract, either to
default or to user-defined values.
pragma solidity ^0.4.0;
contract member{
string name;
uint age;
constructor(string _name, uint _age){
name=_name;
age=_age;
}
}
4. + 9 1 9 5 0 1 7 0 7 7 4 1 T U T O R I A L S D I A R Y
confidential @Tutorials Diary | www.tutorialsdiary.com
Facts
A constructor set as internal causes the contract to be marked as abstract.
Constructor can be invoked by following two ways.
contract teacher is member ("Vikas", 32){}
contract teacher is member {
constructor(string _N, uint _age) member(_N,_age) public{}
}