First things that comes in mind are
- A class is a blueprint from which objects are created.
- They are wrappers and have everything inside them e.g Functions/Methods/Variables etc.
- They can be public or default but not private or protected.
- Each Class has a name, and may belong to a package.
- A class can have both static and non static methods and variables.
- A class can not be static (however inner classes can be).
Definition
A class is the blueprint from which individual objects are created. A class containes- A main method marked as public static void and taking an array of String arguments.
- Instance variables that are inside a class but outside all function.
- Local variables that are inside a function. Their scope is limited to the function only.
- Member functions that can be either static, non static or final or final static.
- A package declaration, this is important for grouping same type of classes together.
package com.ekiras.demo;
public class HelloWorld{
int instanceVarible = 1;
public static void main(String args[]){
System.out.println("HelloWorld");
}
public void method(){
String localVariable = "Hi";
}
}
A simple class may look like the one shown above.
Access specifiers of a class
A class can have public or default access specifier. The class can not be private or protected.
Comments
Post a Comment