Question

What are constructors? Explain why they are needed in an object-oriented programming language. If inheritance takes...

What are constructors? Explain why they are needed in an object-oriented programming language. If inheritance takes place, what is the order in which the parent and child constructors are called? Can a constructor be overloaded? Can a constructor be overridden?

Explain when a destructor should be declared as virtual in C+?

Explain the use of the access specifiers public, protected and private in C++. Which is the default specifier?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Constructors are the blocks which are used to assign values to the variables.

Constructors call themselves unlike methods or functions means no need to call construtors .

If Inheritance takes place then first child constructors get the values from objects even child constructors hold the values of parent constructors also.

ParentConstructor(variableP)

{

}

ChildConstructor(VariableP,VariableC) : ParentConstructor(VariableP)

{

}

Yes, Constructor can be overloaded .One class can have multiple constructors.

No , a constructor can't be overridden.

when a destructor should be declared as virtual in C++, When there is at least one virtual function & an variable is  no more in used .

In Public access specifier, public data member  or data function or constructor are accessible globally and outside the class also.

In private access specifier, private data member  or data function or constructor are accessible within the class only.

In protected access specifier, public data member  or data function or constructor are accessible in child class only.

private is the default specifier in c++.

.

Add a comment
Know the answer?
Add Answer to:
What are constructors? Explain why they are needed in an object-oriented programming language. If inheritance takes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Discuss the importance of the protected access modifier. Provide examples of when to make parent class...

    Discuss the importance of the protected access modifier. Provide examples of when to make parent class data fields private versus protected and how a derived class can access the constructor of its parent class. Consider how the parent/child relationship is enforced with the keyword and the importance of inheritance in application development. Also, discuss how multiple inheritance is commonly used in object-oriented programming languages.

  • In object-oriented programming, the object encapsulates both the data and the functions that operate on the...

    In object-oriented programming, the object encapsulates both the data and the functions that operate on the data. True False Flag this Question Question 101 pts You must declare all data members of a class before you declare member functions. True False Flag this Question Question 111 pts You must use the private access specification for all data members of a class. True False Flag this Question Question 121 pts A private member function is useful for tasks that are internal...

  • As an object oriented language, Java obviously provides support for composition and inheritance. Let's start off...

    As an object oriented language, Java obviously provides support for composition and inheritance. Let's start off by describing how Java specifies that one class inherits from another class. Are there any restrictions on inheritance in Java that distinguish it from C++? How does a derived class override a base class method? How does an overridden method invoke a base class method? How does the derived class constructor invoke an explicit value constructor from the base class? Note: Plagiarism is checked...

  • Match the following: Inheritance: Encapsulation: Polymorphism: Modularization: Separation of concerns: DRY Principle: Object oriented programming: Procedural...

    Match the following: Inheritance: Encapsulation: Polymorphism: Modularization: Separation of concerns: DRY Principle: Object oriented programming: Procedural programming: Matlab is heavily used in: Python is heavily used in: [Choices are]: Child classes automatically get properties and methods of parents Outlines the procedure by which pseudo-code is turned into code Large-scale consumer commercial software programs Properties and methods can be private, protected or public The fastest growing language in terms of popularity Most modern large-scale software programs Breaks down a program into...

  • Java - Object Oriented Programming Declare a class named Customer that has two private fields? Write...

    Java - Object Oriented Programming Declare a class named Customer that has two private fields? Write a set method to make sure that if age > 125 years or less than 0 then it is set to 0 (default value) What does it indicate when declaring a class's instance variables with private access modifier? What is the role of a constructor? The data part of by an object's instance variables is known as? Do all methods have to always return...

  • (1)     ____ is the principle that allows you to apply your knowledge of a general category...

    (1)     ____ is the principle that allows you to apply your knowledge of a general category to more specific objects.           a.       Inheritance              c.       Encapsulation           b.       Polymorphism                    d.       Override (2)     When you create a class by making it inherit from another class, you are provided with data fields and ____ automatically.           a.       fonts                      c.       class names           b.       methods                  d.       arrays (3)     By convention, a class diagram contains the ____ following each attribute or...

  • please help me with this in C# language. Constructors The goal for this exercise is to...

    please help me with this in C# language. Constructors The goal for this exercise is to understand what constructors are, how to define them, and how to call them, including ‘default’ constructors, and including the use of overloading to provide multiple constructors. One of the advantages of having a clear separation between the public interface of an object and private internal implementation of an object is that once you've got the data in the object you can then ask the...

  • (JAVA) In your own words, explain the following object-oriented programming principles: abstraction encapsulation inheritance polymorphism

    (JAVA) In your own words, explain the following object-oriented programming principles: abstraction encapsulation inheritance polymorphism

  • Page 1/2 ECE25100 Object Oriented Programming Lab 8: Inheritance Description: The purpose of this lab is...

    Page 1/2 ECE25100 Object Oriented Programming Lab 8: Inheritance Description: The purpose of this lab is to practice inheritance. To get credit for the lab, you need to demonstrate to the student helper that you have completed all the requirements. Question 1: Consider the following detailed inheritance hierarchy diagram in Fig. 1. 1) The Person.java constructor has two String parameters, a first name and a last name. The constructor initializes the email address to the first letter of the first...

  • Question 1 10 pts Inheritance is a capability of C++ to represent increased specialization that is...

    Question 1 10 pts Inheritance is a capability of C++ to represent increased specialization that is often found in real world relationships. True False Question 2 10 pts Inheritance between a child and parent object exhibits an 'relationship. Question 3 10 pts As you move down an inheritance relationship from parent to child, you typically move from a general to specific description. True False Question 4 10 pts The syntax for declaring DerivedClass to publicly inherit from BaseClass is given...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT