On p. 579 and then again on p. 586 Savitch drives home a point about the syntax
ID: 3825333 • Letter: O
Question
On p. 579 and then again on p. 586 Savitch drives home a point about the syntax of invoking a constructor -what you SHOULD do when invoking a no-arg constructor, and what you should NOT do. Though he doesn't mention it, this is a "trap" that many C++ learners fall into if they learned Java first, because this is a place where C++ and Java syntax differ significantly. Suppose you have a no-arg constructor for a class Student. a. What is the correct syntax to declare a local variable inside a function or method called s that is of type student, and is created with the no-arg constructor? b. What is the "wrong" syntax for doing that same thing that Savitch specifically warns against doing? c. In one of the passages where this is explained, Savitch indicates WHY this other syntax is wrong if your intention is to make s an instance of class student. This syntax actually has a completely different meaning in C++. What does this alternate syntax mean-that is, what would s be declared to be under this alternate syntax?}Explanation / Answer
Dear I did not get what you want to say
but as per question i can give my idea
basically we have three consutructor in a class
1. Defualt
2. Parameterised
3. Copy Constructor
these above constructors are use in both C++ & Java
Default Constructor - It automitically called when object created
Parameterized Constructor- when we pass some value in object then it work
Copy Consutructor - when you pass the object
for exp in c++
class a
{
in a1 ;
in b1 ;
public
a()
{
cout<<"default Cons";
}
a(int e ,int f)
{
a1=e,b1=f;
}
a(a ob1)
{
a1=ob1.a1
b1=ob1.b1
}
};
void main()
{
a ob; -default consutructor called
a ob1(3,4) - parameterized consutuctor called
a ob2(ob1) copy con called
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.