When does Java use internal class __java

Source: Internet
Author: User

Java in the internal classes and interfaces together, can be resolved often by C + + programmers complain that there is a problem in Java not much inheritance.

Each inner class can be inherited independently from one (interface) implementation, so no matter whether the outer class has inherited an (interface) implementation, it has no effect on the inner class.

1. Internal class inheritance

Because the constructor of an inner class must be connected to a reference to its outer class object, special syntax is used when inheriting the inner class. The problem is that a reference to a perimeter class object must be initialized, and there is no default object to connect to in the exported class. Therefore, it is necessary to use special grammar to make clear the relationship between them.

Class withinner{
    class inner{}
} public

class Inheritinner extends withinner.inner{
    Inheritinner ( Withinner WI) {
	    wi.super ();
	}
}

2 Internal class coverage

When inheriting a peripheral class, the inner class does not change. Changes occur when an internal class is explicitly inherited.

public class Egg {
	private yolk y;

	Protected class Yolk {public
		yolk () {
			System.out.println ("Egg.yolk");
		}

	Public Egg () {
		System.out.println ("New Egg");
		y = new yolk ();
	}
}
public class Bigegg extends Egg {public
	class yolk {public
		yolk () {
			System.out.println ("Bigegg.yolk ()"); c3/>}
	} public

	static void Main (string[] args) {
		new Bigegg ();
	}
}
Output:

New Egg
Egg.yolk

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.