The path to Java Learning (vi)

Source: Internet
Author: User

1: Package and access rights

To place a class in a package, you need to use the package name
The use of the-d parameter at compile time the function of this parameter is to generate the corresponding folder according to the package name
The whole of a class should be "package name" + "." + "class name"

Naming conventions for package names:
Require that all letters of the package name be lowercase
Package name in general, is your domain name upside down write

A class in a package accesses the conditions of a class in another package
1: I'll make a bag.
1: Access class Import Package name
2: The accessed class must be public

Under the above conditions: if you want a class to access the properties and methods of another class, they must be public


Public own packages and other classes in the package can be accessed  
private only their own classes can access the
(default) your own package can be accessed,
protected can only modify variables and methods and be accessible only by its subclasses outside the package.

2: interface

Defining an interface is equivalent to defining the criteria for calling an object

Basic syntax for interfaces
1: Using interface definition
2: The methods in the interface are abstract methods
3: The methods in the interface are public permissions

4: Implement interface using implements keyword
5: A class can implement multiple interfaces
6: An interface can inherit multiple interfaces

The path to Java Learning (vi)

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.