For the following code, choose the correct option. [code] class A { int marks; protected : A() { marks=100; } public : A( int

Nguyễn Pháp

New member
For the following code, choose the correct option.
Code:
class A
{  
	int marks;
	protected : A()
	{ 
		marks=100; 
	}
	public : A( int x)
	{ 
		marks=x;  
	}
};
A. The instances can be created only in subclasses
B. The instances can be created only in main() function
C. The instances can be created only in parent class
D. The instances can be created anywhere in the program
 
Answer: d
Explanation: The instances can be created anywhere in the program. The only restriction will be on which constructor will have to be called. The instances with zero arguments will be allowed to be created only inside the subclasses, but the instances with one argument can be created anywhere in the program.
 

Tìm kiếm

Back
Top