adspace


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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What if I write static public void instead of public static void?

938


What do you understand by casting in java language? What are the types of casting?

924


Can we extract main method from another class?

1035


What is the locale class?

1027


How does java handle integer overflows and underflows?

1116


what is reflection api? How are they implemented?

1106


What is the java api?

999


Are jvm’s platform independent?

983


What is the first argument of the string array in main method?

1031


What is the resourcebundle class?

1013