Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6010263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:05:28+00:00 2026-05-23T02:05:28+00:00

i have one doubt in mind that…. 1) we can call & access any

  • 0

i have one doubt in mind that….

1) we can call & access any static method or variable from any non static method but from static method we can not access any non static method or variable…..why.

2) but we can create a instance of any class from static method.

please tell me the reason to understand better answer of my question.

class Class1
{
    static int x=0;
    int w = 0;
    private static Class2 test()
    {
        w = 88; // give error because w is not a static member.
        test1(); // give error because test1() is not a static function.
        Class2 z = new Class2(); // here i am creating instance of class2
        return z;
    }

    private int test1()
    {
        x = 9;
        return x;
    }
}

class Class2
{

}

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:05:29+00:00Added an answer on May 23, 2026 at 2:05 am

    To understand the reason why you’d first have to understand the difference between a class and an actual object.
    I can define a class like the following:

    public class Car
    {
      public string Brand {get; set;}
    }
    

    What i will be telling the compiler by this is what a Car would look like if i where to create such a thing. No Car is created at this point but the computer has an understanding of what a car is. We have given it a blueprint. This is called a class

    Next i can go and actually create a car:

    Car myCar = new Car();
    myCar.Brand = "Ford";
    Car otherCar = new Car();
    otherCar.Brand = "BMW";
    

    Now myCar contains an actual object and i told the computer it is a car. I also created another car in otherCar. These are both individual objects. and both have their own Name belonging to the object.

    So now we have 2 objects but still only 1 class.

    Now sometimes the need may arise for properties of methods that have some link to the concept Car but don’t require a specific Car to work on. in C# we can define such members using the static keyword.

    We can add the following method to our class:

    public static Car GetFirstCarEverBuild();
    

    To actually find the first car that was ever build we do not need access to a specific car. we will try to find a car here but we don’t start out with one. so we mark it static. this also means that we have to access to Brand of the car since we have no object to get it from. The case might even be that no Car at all was ever created in wich case the method can just return Null. No car has ever existed and you don’t need one to find that out.

    the same goes for static fields and properties:

    public static Car firstCar;
    

    This field can store 1 car and 1 only. no matter how many cars you create. it’s value is tied to the class and not the object. So if myCar will store a value in this field then otherCar can read this same value.

    Consider the following example to sum it all up:

    public class Car
    {
      public static Car firstCar;
    
      public Car()
      {
        if (firstCar == null)
          firstCar = this;
      }
    
      public string Brand {get; set;}
    
      public static Car GetFirstCarEverBuild()
      {
        return firstCar;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one doubt concerning c# method overloading and call resolution. Let's suppose I
I have one doubt in string . How can we acess the memory of
In following program . I have one doubt. I have declared one global variable
I have one doubt regarding audio processing for noise reduction. Is there any free
I have one doubt that how to get other control's value when we select
i have one doubt, that is when we create one-to-many as bidirectional. we will
I have a doubt whether NSDate can be directly stored or read from the
I have a doubt regarding database operation.I have one insert query that should run
I have one doubt regarding casting. public void Test(out T a, out T b)
I have a doubt in layouts.I have designed one layout using group layout using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.