C# Programming - Structures - Discussion
Discussion Forum : Structures - General Questions (Q.No. 15)
15.
Which of the following statements are correct about the structure declaration given below?
struct Book
{
private String name;
protected int totalpages;
public Single price;
public void Showdata()
{
Console.WriteLine(name + " " + totalpages + " " + price);
}
Book()
{
name = " ";
totalpages = 0;
price = 0.0f;
}
}
Book b = new Book();
- We cannot declare the access modifier of totalpages as protected.
- We cannot declare the access modifier of name as private.
- We cannot define a zero-argument constructor inside a structure.
- We cannot declare the access modifier of price as public.
- We can define a Showdata() method inside a structure.
Discussion:
1 comments Page 1 of 1.
Raj said:
7 years ago
B is an incorrect answer. No 5 is allowed in the struct. A struct can have methods. Since struct does not support inheritance no. 1 holds. 3 holds as well since a no-arg constructor is automatically generated by the compiler which assigns the default parameter values.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers