-No enclosing instance of type Test is accessible. Must qualify the allocation with a enclosing in

Source: Internet
Author: User
Tags static class
-No enclosing instance of type Test is accessible. Must qualify the allocation with a enclosing instance of type Test (e.g. X.new A () where x

is an instance of Test).



public class Test {public

	static void Main (string[] args) {
		test test = new test ();
		Beans XM = test.new Beans ();

	}
	public class beans{
		
	}

}

X refers to the inner class that I wrote.

According to the hint , there is no instance of an accessible internal class test, and an instance of the appropriate internal class test must be assigned (such as X.new A (), x must be an instance of test. looking at this hint, I wonder, I have already instantiated this class with new, why not yet.

So Baidu Google a bit about the relevant information. The inner Class I wrote is dynamic, which begins with the public class. The main program is public static class main. In Java, a static method in a class cannot call a dynamic method directly. Only an inner class is decorated as a static class, and then the member variable and member method of the class can be invoked in a static class. So the workaround is to change public class to public static class.

or change to the above new Test (). New Beans ():

Of course, if you want to look less bizarre, you can also write another method to instantiate the inner class, and then use an instance of the external class to invoke the method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.