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 8539141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:17:34+00:00 2026-06-11T11:17:34+00:00

Access static method from non static class with object. It is not possible in

  • 0

Access static method from non static class with object.
It is not possible in C#. Where it is done by JAVA.
How it works?

example of java

/**
* Access static member of the class through object.
*/
import java.io.*;

class StaticMemberClass {
    // Declare a static method.
    public static void staticDisplay() {
        System.out.println("This is static method.");
    }
    // Declare a non static method.
    public void nonStaticDisplay() {
        System.out.println("This is non static method.");
    }
}

class StaticAccessByObject {

    public static void main(String[] args) throws IOException {
        // call a static member only by class name.
        StaticMemberClass.staticDisplay();
        // Create object of StaticMemberClass class.
        StaticMemberClass obj = new StaticMemberClass();
        // call a static member only by object.
        obj.staticDisplay();
        // accessing non static method through object.
        obj.nonStaticDisplay();
    }
}

Output of the program:

This is static method.
This is static method.
This is non static method.

How to do this in C#?
thanks in advance..

  • 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-06-11T11:17:35+00:00Added an answer on June 11, 2026 at 11:17 am

    C# forbids referencing a static method through instance.Method, only Type.Method is acceptable. To call a static method, you need to go through the type, not an instance.
    In your case this means that StaticMemberClass.staticDisplay() works, but obj.staticDisplay() does not.


    When a method is referenced in a member-access (§7.6.4) of the form E.M, if M is a static method, E must denote a type containing M, and if M is an instance method, E must denote an instance of a type containing M.

    (C# Language Specification Version 4.0 – 10.6.2 Static and instance methods)

    When a static member M is referenced in a member-access (§7.6.4) of the form E.M, E must denote a type containing M. It is a compile-time error for E to denote an instance.

    (C# Language Specification Version 4.0 – 10.3.7 Static and instance members)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I try to access the Host object from a non-static method declared in
Is it possible to access a child class constant from within a static method
I want to access a static variable from a static method: #!/usr/bin/env python class
Netbeans tells me it's bad to access a static method from a non static
When we have a static method in a class it access only static members
I'm trying to access a static method in a Utils class I created: public
I neet access to current object in a static method. Code: protected static $name;
is it possible to access a static property of a COM object without creating
Is there any other way to access a static variable from a static method,
Why I can access to X variable from method() and not from Main() method?

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.