answersLogoWhite

0

Characteristics of constructor

Updated: 8/11/2023
User Avatar

Wiki User

13y ago

Best Answer

Contains an access modifier followed by the name of the class and some parameters. More specifically:

public class MyClass {

//Constructor

public MyClass() {

}

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

1. You need not code them explicitly. Java will automatically place a default constructor

2. You can pass arguments to the constructor

3. They can return only an object of type of that class

4. They can be made private

5. They would be executed always (Everytime a class is instantiated)

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

I assume you mean the constructor in a programming language. A constructor is a program that runs automatically every time an object is created. Details vary, depending on the language. In Java for example, the constructor has the same name as the class. In some other languages, the constructor has a specific reserved name.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Two key points to remember about constructors are that they have no return type and their names must exactly match the class name

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Characteristics of constructor
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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 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.


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


How many kinds of constructor in java?

Java has 2 types of constructors based on parameters passed:Default or parameter-less constructor: A constructor which does not accept any arguments.Parametrized constructor: A constructor which accepts one or more arguments.Similarly based on Access modifier also we have:Public constructor - Class can be instantiated by anyonePrivate constructor - Class cannot be instantiated by anyoneProtected constructor - Class can be instantiated only by sub classes

Related questions

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 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.


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


Can you call constructor?

yes we can call constructor


What is use of constructor in java?

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


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


What happens when no constructor function is declared in a class - in Java?

When any constructor is deffined in your class, the java compiler create a default no argument constructor for you. This constructor only have an invocation to the super class constructor (" super( ) ").


How many kinds of constructor in java?

Java has 2 types of constructors based on parameters passed:Default or parameter-less constructor: A constructor which does not accept any arguments.Parametrized constructor: A constructor which accepts one or more arguments.Similarly based on Access modifier also we have:Public constructor - Class can be instantiated by anyonePrivate constructor - Class cannot be instantiated by anyoneProtected constructor - Class can be instantiated only by sub classes


Is there a sample program for constructor?

All Java programs would have a constructor... public class Test { public Test(){ ... } ..... } This is a constructor. Even if you dont code the constructor Java would automatically place a default constructor for compilation.


What is another name of default constructor?

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.