answersLogoWhite

0

Can you call constructor

Updated: 8/18/2019
User Avatar

Wiki User

13y ago

Best Answer

yes we can call constructor

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you call constructor
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

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.


How do explicitly invoke superclass constructor from a subclass?

Using the super keyword. If you call super() from within your constructor, it will explicitly invoke the superclass version of the constructor.


Can you implement a constructor in private part of code?

no we cannot initialize a constructor in private in order to call a constructor from outside of a class it must be a public member.in order to create an object we should call the constructor .so only private members can implement outside of the class.


Why there is the need of the constructor if you can assign the value to variables by the help of the methods ..?

A constructor is what allocates memory for an object. If you didn't call a constructor, you would have no object in which to assign values.


How do you call an abstract class from main method?

An abstract class cannot have a constructor and hence you cannot invoke the constructor of the class - i.e., you can instantiate an abstract class and hence you cannot call the constructor of an abstract class.


How does constructor work?

First line in any constructor has to be either super() or this() not both. If any constructor does not contain either of super() and this(), compiler adds super(). When any constructor is called before excuting the code of the constructor, if it founds this(), it will call another constructor else it will call super() which is the call for the constructor of super class, now again from the super class constructor it will call the super class constructor if available. This is continued until it reaches the top of the class hierarchy. ---- Basically, a constructor is a block of code that gets executed each time a particular instance of a class is created. So, say you've designed a class for working with a database of some sort. When you create an instance of that class, copies of all the variables and functions of that class get attached to the instance-object, and if one of the functions is a constructor function, it will be run as soon as the instance-object is created. This lets you automatically set up conditions for the instance (i.e. establishing connections to different databases or reading data from different tables, or etc.). Depending on the language you're using, classes may or may not automatically call the constructor function of a parent or super class (if such exists, and if you do not provide a constructor for the class in question).


Need of constructor in c plus plus?

There is no specific keyword for a constructor in C++. Simply define and declare a method of the class with the same name as the class and it will be a constructor. A constructor with no arguments is the default constructor, a constructor with one argument of class type is the copy constructor, and a constructor with one argument of some other type is the conversion constructor. You can provide other overloaded constructors if you want.


Can you call a constructor from another if a class has multiple constructors?

Yes. All you need to do is to specify the correct number of arguments to invoke the correct constructor.


A subclass can call constructor method defined by its super class?

True


What is first call in struts2 default constructor or validate method?

Default Constructor will be called first . If you override Validate method , then validate method will be called .


How constructor called?

You cannot invoke a constructor explicitly. It will get invoked implicitly when you call the new keyword on the class to create an object of the class. Ex: private ClassExample obj = new ClassExample(); here this new keyword usage on the ClassExample class will invoke the constructor of this class and create an object of that class.


Can a constructor be declared as virtual?

A constructor cannot be virtual because at the time when the constructor is invoked the virtual table would not be available in the memory. Hence we cannot have a virtual constructor. ## Constructor called implicitly not explicitly so constructor is not virtual.