Explain constructor.
Answers were Sorted based on User's Feedback
Answer / kamlesh sharma
constructors are special type of member functions of class
which is used to initilized a object
1. constructors are as same name of the class
2. don't have any return type
3. don't return any value
Types
1 default constructor
2 parametrized constructor and
3 copy constructures
constructors can be overload
Is This Answer Correct ? | 15 Yes | 0 No |
Answer / vinay tiwari
//Constructor is a special member function its name is same
//as class name.It is used to allocate memory to object and
initilizes
//its field .you can also say that it is used to initilized
the object
//constructor invoke automatically when the object of its
class is created
class a
{
public int i;
public a()//default constructor
{
i=10;
}
public a(int x)//parameterized constructor
{
i=x;
}
public a(a ob)//copy constructor
{
i=ob.i;
}
public void display()
{
System.Console.WriteLine(i);
}
}
class b
{
static void Main(string [] args)
{
a ob=new a();
ob.display();
a ob1=new a(77);
ob1.display();
a ob2=new a(ob);
ob2.display();
}
}
Is This Answer Correct ? | 10 Yes | 2 No |
Constuctor is a Method/Fuction
- Having Same Name of that Class(which it belongs to).
- which doesn't have any Return Type.
- and Get Executed Automatically when ever Object is
Created for that class.
Mostly Constuctor is Used for Initialization of Objects.
Is This Answer Correct ? | 6 Yes | 0 No |
Answer / k.gnaneshwar
*-> Constructor is used for initializing the variables
during object creation.
*-> that means the code required for initializing the
variable should be writen in constructor.
CONSTRUCTOR DECLARATION RULES
* Constructor look like a method.
* Constructor have no return type.
* Constructor name should be same name as the class name.
(prog)
class simpleAddition
{
int a,b; //variable declaration
simpleAddition() //constructor declaration
{
a=6;
b=3;
}
int add() // method declaration
{
return a+b;
}
}
output:- 9
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / kousik
Main Advantage of Cons:
1)Object Initialization
2)Class don't have Private access specifier through use of private constructor avoid inheritance.
3)Types:a)static b)Instance
a)--Default automatically crates and no arguments are not supplied.
b)-Same name of class but we have n no of arguments.
Is This Answer Correct ? | 0 Yes | 3 No |
Answer / kamlesh sharma
I am not a Great programmer,i dont know to write a single
line of code also, so i am explaning constructor in words,
without giving you an example program.
frankly to tell, i just watched like a movie when my friend
was typing about constructor,i know only eating, chating,
drinking, sleeping.
My friend just wrote my Name because he don't like to
propagate his name.
And my friend Name is Phani and anyone can contact him at:
phani121@yahoo.co.in, because he is a gem in programming
languages.
Is This Answer Correct ? | 1 Yes | 14 No |
What is an assembly loader?
What is the xml document structure?
Asha buys 16 Chocolates for rs 12 and 24 chocolates for rs 20, if she sold them 30 chocolates for rs 30 then what is the Gain/Loss percentage? Gain(700/19 %) Loss(700/19 %) Gain(500/19 %) Loss(500/19 %) If one person ate 100 grapes in 5 days and 6 more each day from starting, what was the no of grapes he ate on first day? 6 8 10 7 If seven men P, Q, R, S, T, U, V parked his car, P and Q something like that. 6 student J, K, L, M, N, O went for picnic in 2 batches, K and L have to go together, M and O do't go together, if O and L go in one batch then which of these combination will be wrong. Jmnp Jklo klop JKLO a boat can go upstream and down stream, if it goes 5/2 times of downstream at the speed of 6 kmph then what will be the speed of upstream? 15 KMPH 12 KMPH 10 KMPH 11 KMPH A, B, C, D, E sitting on a table, A sits 2 seat left from B and C sits 2 seat right from B then what will not be the combination ACDE
1. What is IIS. pl explain practically. 2. Difference b/w webserver and application server. pl explain practically.
Which type of variables are under the control of garbage collector?
How does array sort work?
what is namespace?
what is uniary operators and binary operators and what is the difference
Explain About a class access specifiers and method access specifiers.
How can you prevent escaping on backslashes in C# with string definitions?
Why do we use anonymous method in c#?
Consider the following pieces of C# code: a. interface I1 {/*......*/} interface I2 {/*......*/} struct Point : I1,I2 {/* ..... */} b. struct Book{ int bookId; struct Book b; } c. using M=Mystruct; struct MyStruct{ int id; } class MyClass{ static void Main(string[] args){ M m = new M(); } } d. struct Sample{ Sample ref x; } Which of the above are correct? Choose one of the options below. a, c and d are right a only right a and c are right d only wrong None of the listed options