Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Explain role of constructor in a java application?

Answers were Sorted based on User's Feedback



Explain role of constructor in a java application?..

Answer / sonal

Without a constructor u cannot make an object or instance
of a class.
Every class must have a constructor. If no constructor is
provided the complier will provide default constructor at
run time.

Is This Answer Correct ?    33 Yes 2 No

Explain role of constructor in a java application?..

Answer / sindhura

A constructor in java has the same name as that of the
class. Whenever the statement such as classname objectname
is encountered, it calls the constructor to initialise the
values for the object. It doesnot return anything and as
soon as the object is created constructor would be called.

ex. : if there is a class called A

A a = new A();
here A a statement would call the constructor immediately
to initialise the values for a object.

Is This Answer Correct ?    10 Yes 1 No

Explain role of constructor in a java application?..

Answer / mr. ashwani hundwani

A constructor is a member function of a class,which gets
automatically called when a class is instantiated(i.e when
object is created),compiler automatically provides default
constructor(with no arguments).
It has same name as that of class
***Constructor is best utilized for initializing the data
members.*****
rather than writing methods to provide the values to data
members we can pass them through consturctor at the time of
instantiation.EX-

import java.util.*;
class shape
{
int length;
public shape(int len)//constructor should be public
{
length=len;
}
}
class abc
{
public static void main(String a[])
{
shape obj=new shape(5);/*passing a integer value to
constructor of class shape*/

}
}

Is This Answer Correct ?    3 Yes 0 No

Explain role of constructor in a java application?..

Answer / harini

The main purpose of construtor is to initialize instance
variables.

Is This Answer Correct ?    4 Yes 1 No

Explain role of constructor in a java application?..

Answer / harsh

Constructor is "object creator".
its role is to create objects thats it.

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More Core Java Interview Questions

Explain the difference between extends thread vs implements runnable in java?

0 Answers  


Why should we create an object? what is a need of it? Apart from access members of a class i want what is a need of object what does it contain?? In normal class to access any member of thaht class we create object where as for static class we access its members using class name. what is a difference between them... thanks in advance.

1 Answers  


What are the advantages of unicode?

0 Answers  


why java is better then .net?

5 Answers   HCL, iGate,


How is a variable stored in memory?

0 Answers  


Which of the following can be referenced by a variable? A. The instance variables of a class only B. The methods of a class only C. The instance variables and methods of a class

2 Answers  


what is a thread?

13 Answers   IBM, SunGard,


Is java 9 released?

0 Answers  


Is static variable stored in heap?

0 Answers  


Explain different forms of polymorphism?

0 Answers  


Difference between vector and arraylist.

0 Answers  


Can we use static class instead of singleton?

0 Answers  


Categories