|
INTERVIEW QUESTIONS
PROGRAMMING LANGUAGES
C++
DETAILS
Question: Define a constructor - What it is and how it might be called (2 methods).
Answer:
constructor is a member function of the class, with the name of the function being the same as the class name. It also specifies how the object should be initialized.
Ways of calling constructor: 1) Implicitly: automatically by complier when an object is created. 2) Calling the constructors explicitly is possible, but it makes the code unverifiable.
Answer2 class Point2D{ int x; int y; public Point2D() : x(0) , y(0) {} //default (no argument) constructor };
main(){
Point2D MyPoint; // Implicit Constructor call. In order to allocate memory on stack, the default constructor is implicitly called.
Point2D * pPoint = new Point2D(); // Explicit Constructor call. In order to allocate memory on HEAP we call the default constructor.
|
|
|
Category |
C++ Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 6572 users |
Added on |
7/16/2015 |
Views |
66575 |
Rate it! |
|
|
Question:
Define a constructor - What it is and how it might be called (2 methods).
Answer:
constructor is a member function of the class, with the name of the function being the same as the class name. It also specifies how the object should be initialized.
Ways of calling constructor: 1) Implicitly: automatically by complier when an object is created. 2) Calling the constructors explicitly is possible, but it makes the code unverifiable.
Answer2 class Point2D{ int x; int y; public Point2D() : x(0) , y(0) {} //default (no argument) constructor };
main(){
Point2D MyPoint; // Implicit Constructor call. In order to allocate memory on stack, the default constructor is implicitly called.
Point2D * pPoint = new Point2D(); // Explicit Constructor call. In order to allocate memory on HEAP we call the default constructor. Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
Anything wrong with this code? T *p = 0; delete p;
|
View Answer
|
|
Anything wrong with this code? T *p = new T[10]; delete p;
|
View Answer
|
|
What is an orthogonal base class?
|
View Answer
|
|
What is an adaptor class or Wrapper class?
|
View Answer
|
|
What is the dangling pointer in c++
|
View Answer
|
|
What is a mixin class?
|
View Answer
|
|
What is a concrete class?
|
View Answer
|
|
What is the handle class?
|
View Answer
|
|
What is an action class?
|
View Answer
|
|
When can you tell that a memory leak will occur?
|
View Answer
|
|
What is a parameterized type?
|
View Answer
|
|
Differentiate between a deep copy and a shallow copy?
|
View Answer
|
|
What is an opaque pointer?
|
View Answer
|
|
What is a smart pointer?
|
View Answer
|
|
What is cloning?
|
View Answer
|
|
Describe the main characteristics of static functions.
|
View Answer
|
|
Will the inline function be compiled as the inline function always? Justify.
|
View Answer
|
|
Define a way other than using the keyword inline to make a function inline.
|
View Answer
|
|
How can a '::' operator be used as unary operator?
|
View Answer
|
|
What are the main underlying concepts of object orientation?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All C++ Interview Questions & Answers - Exam Mode /
Learning Mode
|