A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Source file declaration rules:

What is the Source file declaration rules in Java ?

What is the Source file declaration rules in Java ?

As the last part of this section, lets us know look into the source file declaration rules. These rules are essential when declaring classes, import statements and package statements in a source file. There can be only one public class per source file. A source file can have multiple non-public classes.

The public class name should be the name of the source file as well which should be appended by .java at the end.

For example: The class name is . public class Employee{}
Then the source file should be as Employee.java.

If the class is defined inside a package, then the package statement should be the first statement in the
source file.

If import statements are present then they must be written between the package statement and the class declaration. If there are no package statements then the import statement should be the first line in the source file.

Import and package statements will imply to all the classes present in the source file. It is not possible to declare different import and/or package statements to different classes in the source file.

Classes have several access levels and there are different types of classes; abstract classes, final classes etc. I will be explaining about all these in the access modifiers chapter.

Apart from the above mentioned types of classes, Java also has some special classes called Inner classes and Anonymous classes.












LEARN TUTORIALS

.

.