what is constructer?what are the type of constructer with
example.

Answers were Sorted based on User's Feedback



what is constructer?what are the type of constructer with example...

Answer / sandesh nawadkar

Constructor is a same as method but it isnot exactly a
method . It has same name as a Class. It has access
specifier but not return type. Constructor is used to
create and initialize objects at runtime.
There are different types of constructors in different oop
languages.
e.g. Consider, java language-there are two types:-
1. Default
2. Parameterized.

Is This Answer Correct ?    12 Yes 1 No

what is constructer?what are the type of constructer with example...

Answer / kool

A constructer has same name as class .it does not have any
data type in a program we can only have one constructer
with a class name because they can be overloaded.if we dont
create one the programe creates one for us.

public class kool{

/** constructer

public kool(){
*/
}
}

Is This Answer Correct ?    5 Yes 5 No

what is constructer?what are the type of constructer with example...

Answer / sunil prasad

Constructor is a specail type of mrthod.constructor name
should be same with the class name
There is defferent type of construtor:-
default constructor
parameter constructor
default construtor automatically call when we create
object of class.

Is This Answer Correct ?    1 Yes 1 No

what is constructer?what are the type of constructer with example...

Answer / shiva krishna

class Shiva
{
public Shiva() // it is a constructor
{
//code
}
}
class Mainclass
{
public static void main(String args[])
{
Shiva obj=new Shiva();
}
}

explanation: the code written in constructor is
automatically executed when we create object for the
class.no need to call the constructor/method again.

point to note:
constructor must not have any return type

Is This Answer Correct ?    1 Yes 1 No

what is constructer?what are the type of constructer with example...

Answer / prasad

A constructor is a method.it used to custom intialization
for an object.constructor name and class name is same.
consructor should not return any value not even void also.
A constructor will Executed at the time of initialization of
an object.
Different types of constructors:
--------------------------------
1)default constructor
2)parametarized constructor
Ex:


class sum{
int a,b;//instance variables
sum(int a,int b){
System.out.printl("sum of two numbers="+(a+b));
}
}
class Example{
psvm(String s[])throws Exception{
sum s=new sum(10,10);
}
}
o/p:sum of two numbers=20
/*here the constructor will be executed at the time of
creating the object*/

Is This Answer Correct ?    0 Yes 2 No

what is constructer?what are the type of constructer with example...

Answer / devender

write answer i n 2nd

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More Java Related AllOther Interview Questions

What does public static void main(string[]) mean?

0 Answers  


What is the difference between java se and java ee?

0 Answers  


Are jvm’s platform independent?

0 Answers  


Is php faster than java?

0 Answers  


What is default constructor in java?

0 Answers  






Why do we need framework in java?

0 Answers  


How to implement Thread

2 Answers  


What is jdk for netbeans ide?

0 Answers  


What is lambda expression in mvc?

0 Answers  


What is @resource annotation in java?

0 Answers  


What are struts java?

0 Answers  


Are streams faster than for loops?

0 Answers  


Categories