answersLogoWhite

0

The consttructor creates a new instance of the class

for example the class shown below does not exist until the constructor is called, where it sets the class up for first use.

Class Dog

{

int _legs, _eyes;

string _breed;

//CONSTRUCTOR, this takes an input from the user which sets the breed of the dog, and sets the default number of legs and eyes.

public Dog(input)

{

_legs = 4;

_eyes = 2;

_breed = input;

}

}

if the user calls the constructor with the string "Labrador", that is one instance of the class, if the user calls it again with the string "terrier" that is another instance. the class is constructed like this:

//Class instancename = New class(parameters);

Dog lab = New Dog("Labrador");

hope this helps

Steve

User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

Why is a constructor useful?

Objects are constructed. You can't make a new object without invoking a constructor. In fact, you can't make a new object without invoking not just the constructor of the object's actual class type, but also the constructor of each of its superclasses including the Object class itself! Constructors are the code that runs whenever you use the keyword new.


What does this keyword do?

The term keywords in Search Engine Optimization (SEO) refers to the most important words or group of words in your website content. Keywords play an essential role in the SEO process because search crawlers use them to index your website. Thus, it is essential you understand how to leverage your website keywords for your SEO process to be a success. The "this" keyword is simply a reference to the current object. If, for example, you wanted to add the object you're currently working in to a collection you would want to do something like: // Collection c; c.add(this); --------------------------------------------------- actually,there are 3 uses of 'this' keyword: 1. to refer to the address of the object under consideration. 2. to avoid name space collision. 3. to call a constructor within another constructor.


What does technical knowledge mean?

A person working within the ICT would need to ensure that they have a good understanding of different aspects of their job. For example, an ICT Technician working in a school would need to understand how to fix a computer if there was a problem. That understanding is technical knowledge.


Is ductility a physical property or a chemical property?

Ductility is a physical property because it can be observed without a chemical change to the material. For instance, if we are working with aluminum to calculate its ductility, whatever we do to the aluminum metal in the process, it will still be aluminum metal.


Program that uses struct in c plus plus?

C++ of course uses classes (class) as opposed to structures (struct) for the purpose of keeping data members with an implicit 'private' access specifer as opposed to data members being 'public' by default (as with a struct.) Unless use of external C libs or routines are mandatory and wrapped in the appropriate C header(s), I don't know of any reason to use a struct anywhere in C++.

Related Questions

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


When working with a database it is important to?

Avoid redundancy, for instance.


How sociology help one understand the working of the world?

—How does the study of sociology help one understand the working of the world?


How do you support others to understand and follow safe working practice is?

how to support others to understand and follow safe working practice


Why is a constructor useful?

Objects are constructed. You can't make a new object without invoking a constructor. In fact, you can't make a new object without invoking not just the constructor of the object's actual class type, but also the constructor of each of its superclasses including the Object class itself! Constructors are the code that runs whenever you use the keyword new.


In textbook definitions of key terms are often followed by one or more what that would help make those definitions clear?

Ah, what a lovely question! In textbooks, key terms are often followed by examples that help illuminate their meanings. These examples are like little friends guiding you through the forest of knowledge, making sure you understand each term with clarity and joy. Just remember, it's all about happy little definitions and happy little examples working together to create a beautiful understanding.


In some instance the carm program working group is part of other mission assurance equivalent working groups such as the anti-terrorismforce protection working group?

true


Does your muscluar system help you stay warm?

The muscular does keep your body warm because say for instance you where working out. When working out you sweat, to cool you off and shiver to warm you up so your working out working your muscles.


What do you understand to be the working capital of a business explain?

lind kha lo


Why working experience important?

Let's you understand how your future job will work


What is document area?

The document areas is the main working area when working with electronic documents. For instance, the document area in Microsoft Word is the part of the document you type into.


What do you understand about the work 'info ladies' do in Bangladesh?

Ladies working in iNFO services