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

  • SEARCH
  • Home
  • 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 6108605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:18:48+00:00 2026-05-23T14:18:48+00:00

from static function we can create a instance but we can not access any

  • 0

from static function we can create a instance but we can not access any non-static data member….why.

public static DropoffType DROP_BOX
        {
            get
            {
                DropoffType tempType = new DropoffType();
                tempType.DropoffTypeSelected = _DROP_BOX;
                y=11; // compile time error
                return tempType;
            }
        }

from the above code we can see that instance can be created from property but when we are trying to access any non-static data member then i am getting complile time error. can any one explain the reason in detail that why instance can be created from any where but non-static data member can’t be access from static function.

  • 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-23T14:18:49+00:00Added an answer on May 23, 2026 at 2:18 pm

    If y is an instance field, you can’t access it without telling it which object you mean. For an instance member, there is an implicit this., i.e. this.y.

    Just add:

    tempType.y = 11;
    

    The problem is, you could have any number of variables and objects kicking around. And even for an instance method you often have to disambiguate, i.e.

    public int CompareTo(Foo other) {
        return string.Compare(this.Bar, other.Bar);
    }
    

    (in the above the this. is not strictly needed, but helps the reader IMO; the other. is entirely necessary)

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

Sidebar

Related Questions

Possible Duplicate: Why can I only access static members from a static function? While
Netbeans tells me it's bad to access a static method from a non static
This example is from php.net: <?php function Test() { static $a = 0; echo
Basic question - is it possible to access the current Page from a static
$ javac TestFilter.java TestFilter.java:19: non-static variable this cannot be referenced from a static context
i have a large list of static data from a server that i load
I noticed the function Object.factory(char[] className) in D. But it does not work like
I don't know why but I thought I could statically link a function from
Anyone know how I can dynamically load a control inside of a shared/static function?
I have a function like this public static string GetNumberOfColumns(string ConnectionString) { StringBuilder sb

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.