C# Programming - Constructors - Discussion

Discussion :: Constructors - General Questions (Q.No.4)

4. 

Which of the following statements are correct about static functions?

  1. Static functions can access only static data.
  2. Static functions cannot call instance functions.
  3. It is necessary to initialize static data.
  4. Instance functions can call static functions and access static data.
  5. this reference is passed to static functions.

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

Answer: Option A

Explanation:

No answer description available for this question.

Dheeraj said: (Jul 26, 2011)  
Option 2. Is wrong? static Main () can call instance methods of class.

Penchala Naidu said: (Jun 29, 2012)  
In case of Constructor concept, Static constructor cannot access non-static variables but non-static constructor can access static variables for initialization.

Shiridish said: (Jul 8, 2012)  
2. is wrong. static functions can call instance functions.

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
test t = new test();
int res= t.add(2, 3);
Console.WriteLine(res);
Console.Read();
}
}
class test
{
public int add(int a, int b)
{
int c = a + b;
return (c);

}
}
}

Was said: (Sep 16, 2012)  
Static constructor method cannot access instance method. But other static methods can access instance methods.

Bhavin Umaraniya said: (Oct 2, 2012)  
Dear Shiridish, what you done is that, you instantiated class test itself within static function. You can not access any instance method or variable declared at class level, that means instance method and variables are not accessible to static methods. Because static method and variable assigned with single time memory shared by all instance of that class, then how it decide which instance it belongs to?

Kamal said: (Feb 22, 2013)  
Static function is accessed by static funcation only.

Ganesh said: (Dec 5, 2013)  
If You declare any method as static then the method only access static function and static variable because of static function can by using Class name without creating any instance of that class and non-static member always call by using instance of class.

For that if static function contain any non-static member there is problem occur.

Sank said: (Dec 17, 2013)  
Static members can be accessed by static and non-static methods.

Non-static members can not be accessed by static methods.

It only access static members.

Shafi said: (Dec 29, 2014)  
Static function can call the static methods and also instance methods.

Jaya said: (Oct 21, 2015)  
Answer is A.

Static functions can have both static methods and also non-static methods.

Pravin Magar said: (Apr 22, 2016)  
Yes, you are correct @Jaya.

Static functions can have both methods.

Deepak said: (Oct 7, 2016)  
Please. Don't mention method as function. Method is a method. Try to make improve terminology.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.