Constructors
2 posters
Unix C++ :: UNIX CPP :: CPP :: Example Programs
Page 1 of 1
Constructors
- Code:
#include<iostream>
class Sample
{
int a;
public:
Sample(int a)
{
this->a=a;
}
int getA()
{
return a;
}
};
int main()
{
Sample s;
}
- Code:
#include<iostream>
class Sample
{
int a;
public:
int getA()
{
return a;
}
};
int main()
{
Sample s;
}
Re: Constructors
how this works in java ? I guess default constructor will be called first followed by parameterized constructor(if any).. am i right ?
DineshThangaraju- Posts : 18
Points : 19
Join date : 2010-02-26
Age : 35
Location : India
Re: Constructors
no. if u r creating an object, only one constructor will be called depending on arguments.
Unix C++ :: UNIX CPP :: CPP :: Example Programs
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|