C# Programming - Classes and Objects - Discussion

Discussion :: Classes and Objects - General Questions (Q.No.3)

3. 

Which of the following statements are correct?

  1. Instance members of a class can be accessed only through an object of that class.
  2. A class can contain only instance data and instance member function.
  3. All objects created from a class will occupy equal number of bytes in memory.
  4. A class can contain Friend functions.
  5. A class is a blueprint or a template according to which objects are created.

[A]. 1, 3, 5
[B]. 2, 4
[C]. 3, 5
[D]. 2, 4, 5
[E]. None of these

Answer: Option A

Explanation:

No answer description available for this question.

Sneha said: (Nov 1, 2011)  
The statement "a class can contain friend functiond" is also correct. So except (2) , all are correct.

Rajeev said: (Dec 1, 2011)  
I think we can access Instance member of a class using inheritance;.

So option 1 is wrong.

You need to check it out.

Saurabh Sharma said: (Feb 20, 2013)  
There is no friend function in c# but you can use the 'internal' access modifier which will make this class accessible to the other classes in the same assembly, but not accessible outside the assembly.

Alternatively you can also use 'protected internal' where you restrict access to the current assembly or types derived from the containing class.

Shubhdeep Singh said: (Jun 7, 2013)  
Instance member can be directly accessed by class name if its static. So the first option is improper.

Ramesh Malode said: (Jun 25, 2013)  
You can also use 'protected internal' where you restrict access to the current assembly or types derived from the containing class.

Ramesh Malode said: (Jun 25, 2013)  
Instance member can be directly accessed by class name if its static. So the first option is not correct.

L Sidharth said: (Jul 15, 2014)  
What is instance member?

L Sidharth said: (Jul 15, 2014)  
What is difference b/w class variables and instance variable?

Gloops said: (Aug 2, 2014)  
public class example
{
public static string use = "demonstrate class field";
public int nb;
}

public class program
{
public static void main(string[] args)
{
example e = new example();
e.nb = 3;
Console.WriteLine(example.use);
Console.WriteLine(e.nb);
}
}
}

e is an instance of the class example.

use is a class field, you recognize it with the keyword static. From the program you access it by prefixing it with the name of the class :

example.use

nb is an instance field, you access it by prefixing it with the name of the instance :

e.nb

If you declare three example objects you have three different values of nb, but only one value of use for it is a static field of the class.

Alek said: (May 5, 2015)  
Statement 3 is incorrect, obvious example is system string class:

string s1 = new string ('a', 1) ;

string s2 = new string ('a', 1000) ;

s1 occupies 2 bytes, while s2 occupies 2000 bytes.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.