Constructors and Methods are the heart for our programming languages like java,c#.net,vb.net etc Any developer first know the value of constructors and methods and what are the difference between methods and constructors.How it can be placed in programming development.
Best Description about Constructors in object oriented programming
In object oriented Programming(oops) have many important topics in this constructors is the one of the good topic.Constructors is most relavent asking question in interview purpose for fresher/experience candidates,the frequently asking questions are what is static constructor and dynamic constructor what are the differences.
In constructors we hava two types
1.Static Constructor
2.Dynamic Constructor
Static Constructor:It is Common for all like college name.
Dynamic Constructor:It is Individuals for all like student rollno.
The following Questions and Answers are give a datail explanation about constructors.
1)what is constructor?
Ans:constructor is a member of a class which is special type of function2)constructor can have any return type?
Ans:constructor will not return any value.So it will not have return type.3)Features of Constructor?
Ans:1.class name and construtor name should be same2.constructor can contain parameters
3.constructor can invoke automatically when an object is created.
4)what is instance constructor?
Ans:while defining a constructor if we did not use static keyword it is called as instance constructor.5)what is the purpose of instance constructor?
Ans:purpose of instance constuctor is to initialize instance variables.6)instance constructors can contain parameters or not?
Ans:instance constructor can contain parameters7)what is static constructor?
Ans:while defining a static constructor if we have used static keyword which is called as static constructor.8)what is purpose of static constructor?
Ans:static constructor purpose is to initialize instance variables.9)How to initialize static variable?
Ans:By using static constructor.10)When we will go for static variable?
Ans:Whenever we want to represent a comman value for all objects we will declare as a static variable.11)When class will be loading and when class will be unloading?
Ans:Whenever CLR required to execute any part of the class then it will load concern class from application to CLR.Whenever application execution is completed then all the classes will be unloading.
12)static constructor is a parameterized or parameterless constructor?
Ans:static constructor is a parameterless constructor13)When static constructor will invoke?
Ans:when class is loading static constructor will be invoke automatically.14)When instance constructor will invoke?
Ans:when object is created instance constructor will be invoke15)How many static constructors in one class?
Ans:A class can contain only one static constructor because by default it is a parameterless constructor.16)If a class is having one instance constructor and one static constructor which will execute first?
Ans:First static constructor will execute next instance constructor will execute because class will load first then object will create.Example for static constructor and instance constructor
class Employee{
static Employee()
{
comname="wipro";
}
internal Employee()
{
eno=111;
ename=ram;
esal=5000;
}
Recommended Articles
1.Tutorial of Methods Concept
2.Tutorial of Parameters Passing Mechanism
3.Tutorials of Multiple Inheritance
0 comments:
Post a Comment