‘ { ‘ bracket opens a class and ‘}’ closes it. ‘public class First’ is the line defining a class named “First”.
‘public’ means the class you want to create can be accessible from anywhere. You may use “protected”, “private” later to restrict access to the class. This word is known as “Access Modifier”.
And then “class” is a keyword that signs compiler that you are defining a new class.
That is basic! Following is the real! You might not understand many of notations now. But you’ll later. Every thing in squire brackets are optional and others are keywords.
[accessModifier] [classModifiers] class ClassName [extends SuperClassName] [implements InterfaceList]
{
[classbody]
}
If you are very keen on this tuff class declaration; this is what it says:
[accessModifier] : ‘public’, ‘private’, or other access modifier
[classModifiers] : ‘abstract’ for example, says you can’t create objects using this class. That is another kind of restriction known as Moderation.
class ClassName : Key words we must add to class declaration.
[extends SuperClassName] : Your class become an extend of a supper class.
[implements InterfaceList] : Tells compiler it’s time to use some interfaces with the class, such as ActionListener to sence user clickings.
Java Class Naming Rules
There’re certain rules in java you want to concern when defining a class and known as Syntax of the language.
- A Class Name must begin with a letter of the alphabet (which includes any non-English letter, such as alpha), an underscore or a dollar sign.
- A Class Name can contain only letters, digits, underscores, or dollar signes.
- A Class Name cannot be a java programming language reserved keyword. (Such as ‘public’, ‘class’)
- A Class name cannot be one of the following values: “true”, “flase” or “null
Class Names are conventionally starts with capital letters as it is easy to distinguish class names from other names you used for various other components. And be careful Java is Case Sensitive!
No comments:
Post a Comment