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?

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are scalar data types?

1121


Why are the methods of the math class static?

1122


Can string be considered as a keyword?

1079


What do you understand by the bean persistent property?

1064


What do you understand by classes in java?

1043


What is a layout manager and what are different types of layout managers available in java awt?

1308


What is args length in java?

1234


Explain different states of a thread in java?

1112


What is autoboxing and unboxing?

1060


What is the difference between Error, defect,fault, failure and mistake?

1239


What are the differences between string, stringbuffer and stringbuilder?

1081


What happens when a thread cannot acquire a lock on an object in java programming?

1071


Can you make a constructor final in Java?

1187


What is the purpose of a parameter?

1135


What is time complexity algorithm?

1094