Wednesday, January 28, 2015

More tips towards your Java world


Initialize multiple variable in same line
private int a,b,c,d;
a = b = c = d = 0;

Access Modifier in Java

Access Levels
Modifier Class Package Subclass World
public Y Y Y Y
protected Y Y Y N
no modifier Y Y N N
private Y N N N


Note : "No moidifier" can also call as package-private. Only difference between protected and package-private is protected modifier can be access in subClass.

Why static method can only have static variables & static methods ? 
When you run your java program, static methods call first. So, the methods and variables inside should also be static in order for the static method to be executable.

'final' keyword
final class cannot be superclass (Cannot Inherited by class)
final variable cannot be overwritten. Like constant
final method cannot be override. (Mostly final method will be used in abstract class)

No comments :

// Below script tag for SyntaxHighLighter