answersLogoWhite

0


Best Answer

A default constructor is one that has no parameters (C++ also calls constructors with all default parameters a default constructor), while a parameterized constructor is one that has at least one parameter without a default value. Default constructors can be provided by the compiler if no other constructors are defined for that class or any class the class inherits from, while parameterized constructors must always be defined by the developer.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between default constructor and parameterized constructor?
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 mean constructor in java?

A parameterized constructor in java is just a constructor which take some kind of parameter (variable) when is invoked. For example. class MyClass { //this is a normal constructor public MyClass(){ //do something } //this is a parameterized constructor public MyClass(int var){ //do something } //this is another parameterized constructor public MyClass(String var, Integer var2){ //do something } }


How do you get a default constructor?

The default constructor is an empty (only call the super constructor) with no parameters constructor inserted by the java compiler when you don't define a constructor in your class. If you write something like this: public class NoConstructorClass{ //no constructor goes here } Then you get something like this: public class NoConstructorClass{ public NoConstructorClass(){ // Default constructor that you didn't write super(); } }


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.


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

What is a default parameterized constructor?

There is no such thing as a default parameterized constructor. The default constructor is always the 'no-arg' constructor and does not take any parameters or arguments as input


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 mean constructor in java?

A parameterized constructor in java is just a constructor which take some kind of parameter (variable) when is invoked. For example. class MyClass { //this is a normal constructor public MyClass(){ //do something } //this is a parameterized constructor public MyClass(int var){ //do something } //this is another parameterized constructor public MyClass(String var, Integer var2){ //do something } }


How do you get a default constructor?

The default constructor is an empty (only call the super constructor) with no parameters constructor inserted by the java compiler when you don't define a constructor in your class. If you write something like this: public class NoConstructorClass{ //no constructor goes here } Then you get something like this: public class NoConstructorClass{ public NoConstructorClass(){ // Default constructor that you didn't write super(); } }


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.


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.


How is the default constructor equivalent to a constructor having default arguments?

Any constructor that can be invoked without explicitly passing any arguments is a default constructor. Note that there can be only one default constructor so there can only be one constructor where all arguments have default values or one constructor that has no arguments, but not both. A constructor where all arguments have default values is a useful means of combining two or more constructors into a single default constructor, thus reducing verbosity and code duplication.


What is the difference between implicit and explicit Java programming?

Explicit means done by the programmer. Implicit means done by the JVM or the tool , not the Programmer. For Example: Java will provide us default constructor implicitly.Even if the programmer didn't write code for constructor, he can call default constructor. Explicit is opposite to this , ie. programmer has to write .


What is another name of default constructor?

No-Arg Constructor


What is an empty constructor?

An empty constructor takes no arguments and calls the default constructor


What is the need of parameterized constructor?

Parametrized constructors are used to increase the flexibility of a class, allowing objects to be instantiated and initialised in more ways than is provided by the default and copy constructors alone. If you define any parametrized constructor, including a copy constructor, you will lose the default constructor generated by the compiler and must declare your own if you need one. The default constructor can also be parametrized, but each parameter must include a default value in the declaration, so that it can be called without any parameters.


What is the difference between initialize of elements in a class with the use of constructor and without use of it?

when initializing a class elements by using constructor it will assigned to the elements when object creation is going on. by using other ways the elements will be initialize with default values when object creation