UrbanPro

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

What exactly the work of constructor( default, parameterized) especially about instance variables initialization. Suppose user initialize the instance variables explicitly. Then what is the use of parameterized constructor over here.. Please reply me

Asked by Last Modified  

17 Answers

Learn Java

Follow 0
Answer

Please enter your answer

Software Developer, Expertise in Java/J2ee Technology.

Construct as the name suggest are used to construct the object. So, they are invoked only once and that too at the time of object creation. Default Constructor : Initialize all the instance variables with their default values. Parameterized Constructor : Are used to initialize the instance variables...
read more
Construct as the name suggest are used to construct the object. So, they are invoked only once and that too at the time of object creation. Default Constructor : Initialize all the instance variables with their default values. Parameterized Constructor : Are used to initialize the instance variables at the time of object creation. 1. There are scenarios where the values of instance variables are known at the time of object creation, so in these scenarios parameterized constructors helps to avoid explicitly initialization of instance variable. 2. There are scenarios where the values of instance variables are not known at the time of object creation, in those scenarios, explicit initialization may be needed on basis of application requirement. read less
Comments

Software Developer, Expertise in Java/J2ee Technology.

Exact work of constructor Or Construction of Object :- It allocates the memory for the object in heap memory. It counts the number of bytes of memory by adding all the instance variable memory sizes. (For eg : int 4 bytes, byte 1 byte etc).
Comments

Constructor is mainly used to access the non static members inside the class by using object and to initialize the class members.
Comments

Computer Tutor

Constructor is used to initialize an object at the time of creation. A default constructor is provided by the compiler itself if no constructor is provided by the user. It initializes the state of the object to its default values. Parameterized constructor is used to provide values to the object at the...
read more
Constructor is used to initialize an object at the time of creation. A default constructor is provided by the compiler itself if no constructor is provided by the user. It initializes the state of the object to its default values. Parameterized constructor is used to provide values to the object at the time of creation. If you want to set the values later, after the creation of the object then one can use setter methods to set values. read less
Comments

Java/J2ee,Hibernate,Spring,Oracle,webservices Trainer

Constructor is mainly used to access the non static members inside the class by using object and to initialize the class members.
Comments

Sun Certified Java Professional

Suppose your program is as follows class ABC{ int x; ABC(){ x=10; } } After compilation it becomes as follows: class ABC extends java.lang.Object{ int x; ABC(){ //data member is initialized by default value x=0; // now you statement is copied x=10; ...
read more
Suppose your program is as follows class ABC{ int x; ABC(){ x=10; } } After compilation it becomes as follows: class ABC extends java.lang.Object{ int x; ABC(){ //data member is initialized by default value x=0; // now you statement is copied x=10; } } That is either you initialize your data or not, the constructor will do initialization of instance variable by its default value. 0 for int, 0.0f for float, 0.0 for double type, null for any Object type like String. Parameterized constructor is used to pass some value to set into data member just at the time of creating instance/object of a class. read less
Comments

Java Technical Leader

Look to be specific parametrized constructor are useful for populate those instances which are must/or required for a object. If a particular instance vairable value is optional you can set it via setter. It is purly design decision
Comments

Computer Savvy Professional

A constructor call is more complicated than an ordinary subroutine or function call. It is helpful to understand the exact steps that the computer goes through to execute a constructor call: First, the computer gets a block of unused memory in the heap, large enough to hold an object of the specified...
read more
A constructor call is more complicated than an ordinary subroutine or function call. It is helpful to understand the exact steps that the computer goes through to execute a constructor call: First, the computer gets a block of unused memory in the heap, large enough to hold an object of the specified type. It initializes the instance variables of the object. If the declaration of an instance variable specifies an initial value, then that value is computed and stored in the instance variable. Otherwise, the default initial value is used. The actual parameters in the constructor, if any, are evaluated, and the values are assigned to the formal parameters of the constructor. The statements in the body of the constructor, if any, are executed. A reference to the object is returned as the value of the constructor call. The end result of this is that you have a reference to a newly constructed object. read less
Comments

ICT provide computer education such as a Engineering,School Subjects, Graphics & Web Design

Here, difference between how to object created.
Comments

Trainer

Constructor in java is a special type of method that is used to initialize the object. Java constructor is invoked at the time of object creation. It constructs the values i.e. provides data for the object that is why it is known as constructor. Rules for creating java constructor There are...
read more
Constructor in java is a special type of method that is used to initialize the object. Java constructor is invoked at the time of object creation. It constructs the values i.e. provides data for the object that is why it is known as constructor. Rules for creating java constructor There are basically two rules defined for the constructor. Constructor name must be same as its class name Constructor must have no explicit return type Types of java constructors There are two types of constructors: Default constructor (no-arg constructor) Parameterized constructor read less
Comments

View 15 more Answers

Related Questions

What are the benefits of attending Java coaching classes?
Today Java is the basic requirement for the software industry by learning advanced concepts in java you will have a very good job prospective's. Even if you want to learn BIg Data, testing tools ect.....
Selvi
0 0
5
Why we are using this keyword in Java?
"this" keyword is use to refer an object of current class it is also use for call specific constructor of current class if more than one constructor is declared.
Kiran
0 0
9
Who can provide good Java training with real-time but not institute?
I provide industry specific training to students. If interested check my profile. I used to provide training in Big Data, Java, Scala and Spark too.
Sridevi
0 0
6
Hi, We provide online instructor-led training. I am looking for Java Teacher/Instructor who can teach java via online. If anyone interested then contact me. I have to start the class from tomorrow onwards.
Hi, If you haven't finalised yet, I am interested in being an instructor. I will be teaching the newest version of Java, Java 10. Experience - 3 yrs as Software Engineer, BTech CSE, teaching Java to school and college students since 3 yrs.
Ujjwal Rana
What is the advantage of Java?
Java is object-oriented. This allows you to create modular programs and reusable code. Java is platform-independent. One of the most significant advantages of Java is its ability to move easily from one computer system to another
Kripal
0 0
5

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Differences Between HashMap vs HashSet In Java.
HashSet HashMap HashSet implements Set interface. HashMap implements Map interface. HashSet stores the data as objects. HashMap stores the data as key-value pairs. HashSet...

Java Hash Map internal implementation
1.Hash Map internal implementation: In hash map it will create an array of table (to store the {Key,Value} pair) which is of type java.util.HashMap.EntryThe Entry object contains {hash, key, next, value}...
R

Class and Objects in Java
Class is a template or a blueprint which is used to describe an object. On other hand Object is a reference of a class which follows all the stuff written inside the class. How about taking the whole tour in the following video

How can everyone prepare to clear any Java interview?
Java interview your java should be much strong then J2EE. core java and Advance java is the basic foundation for Interview. Some of the topic about which you should know before going for a java interview...

Recommended Articles

In the domain of Information Technology, there is always a lot to learn and implement. However, some technologies have a relatively higher demand than the rest of the others. So here are some popular IT courses for the present and upcoming future: Cloud Computing Cloud Computing is a computing technique which is used...

Read full article >

Before we start on the importance of learning JavaScript, let’s start with a short introduction on the topic. JavaScript is the most popular programming language in the world, precisely it is the language - for Computers, the Web, Servers, Smart Phone, Laptops, Mobiles, Tablets and more. And if you are a beginner or planning...

Read full article >

Java is the most famous programming language till date. 20 years is a big time for any programming language to survive and gain strength. Java has been proved to be one of the most reliable programming languages for networked computers. source:techcentral.com Java was developed to pertain over the Internet. Over...

Read full article >

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more