Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
Define a constructor - What it is and how it might be called (2 methods).
Define a constructor - What it is and how it might be called (2 methods).
✍: Guest
Answer1
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.
2012-02-03, 2638👍, 0💬
Popular Posts:
How To Change System Global Area (SGA)? - Oracle DBA FAQ - Introduction to Oracle Database 10g Expre...
What are the two fundamental objects in ADO.NET ? Datareader and Dataset are the two fundamental obj...
How will you freeze the requirement in this case? What will be your requirement satisfaction criteri...
What is more advisable to create a thread, by implementing a Runnable interface or by extending Thre...
Rachel opened her math book and found that the sum of the facing pages was 245. What pages did she o...