answersLogoWhite

0

Which situation constructor is used

Updated: 12/23/2022
User Avatar

Wiki User

11y ago

Best Answer

Constructor is necessary when you are about to use instance of a class.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Which situation constructor is used
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

When a object is passed to a function as argument why it is not generating an error if the parameterized constructor is defined and not the default constructor?

default constructor is used only when the programmer does not use a constructor to initialize objects. Once the programmer defines a constructor then the default constructor is no longer used


What is concession constructor?

Constructors are basically used to evoke methods of a class creating its object..and as far as i know there is no constructor called concession constructor..


Why you use constructor instead of function?

For every class an empty constructor will be defined automatically by default unless you provide a constructor definition manually. Constructor in a class can be used to initialize variables or perfrom some basic functionallity whenever an object is created.


What is a constructor and its mandatory to use constructor in a class?

Constructor is a special block of code similar to the method that is used to initialize the state of objects. If you do not define a constructor in a class, Java compiler automatically put a default constructor in the class.


Default constructor in java?

If you don't type a constructor into your class code, a default constructor will be automatically generated by the compiler. The default constructor is ALWAYS a no-arg constructor. (Obviously the compiler has no clue what all arguments you might want for your class. So it takes the safe way out with a no argument constructor) A no-arg constructor is not necessarily the default (i.e., compiler-supplied) constructor, although the default constructor is always a no-arg constructor. The default constructor is the one the compiler provides! While the default constructor is always a no-arg constructor, you're free to put in your own no-arg constructor.

Related questions

When a object is passed to a function as argument why it is not generating an error if the parameterized constructor is defined and not the default constructor?

default constructor is used only when the programmer does not use a constructor to initialize objects. Once the programmer defines a constructor then the default constructor is no longer used


What is use of constructor in java?

Constructor is used to do something (written in constructor) immediately after object creation.


What is concession constructor?

Constructors are basically used to evoke methods of a class creating its object..and as far as i know there is no constructor called concession constructor..


What is conustrutor?

A constructor is a function in C which has the same name of the class. The constructor can be used to initialize some function.


Static can be used in front of a constructor?

No. Static elements belong to the class, and the constructor belongs to the object (which is an instance of a class).


Can you define the constructor as private?

Yes, you can. Making a constructor private ensures that no other class can instantiate that class you just created with a private constructor. It is usually used in Singleton Patterns.


Why you use constructor instead of function?

For every class an empty constructor will be defined automatically by default unless you provide a constructor definition manually. Constructor in a class can be used to initialize variables or perfrom some basic functionallity whenever an object is created.


What is a constructor and its mandatory to use constructor in a class?

Constructor is a special block of code similar to the method that is used to initialize the state of objects. If you do not define a constructor in a class, Java compiler automatically put a default constructor in the class.


Default constructor in java?

If you don't type a constructor into your class code, a default constructor will be automatically generated by the compiler. The default constructor is ALWAYS a no-arg constructor. (Obviously the compiler has no clue what all arguments you might want for your class. So it takes the safe way out with a no argument constructor) A no-arg constructor is not necessarily the default (i.e., compiler-supplied) constructor, although the default constructor is always a no-arg constructor. The default constructor is the one the compiler provides! While the default constructor is always a no-arg constructor, you're free to put in your own no-arg constructor.


What is an empty constructor?

An empty constructor takes no arguments and calls the default constructor


What does it mean in java when a constructor is undefined?

When a constructor is not define in java then the instance used in class is not optimised the value and therefore some times it generates some garbage value. By the way , When we not define a constructor then generally it not distrub the execution of the program.


What is the difference between implicit and explicit call of constructor in c plus plus?

An implicit constructor call will always call the default constructor, whereas explicit constructor calls allow to chose the best constructor and passing of arguments into the constructor.