Skip to main content

Posts

Showing posts with the label Language Fundamentals

static keyword in Java

The  static keyword  is used in java mainly for memory management. We may apply static keyword with variables, methods, blocks and nested class. The static keyword belongs to the class than instance of the class. The static can be: variable (also known as class variable) method (also known as class method) block nested class 1) static variable If you declare any variable as static, it is known static variable. The static variable can be used to refer the common property of all objects (that is not unique for each object) e.g. company name of employees,college name of students etc. The static variable gets memory only once in class area at the time of class loading. Advantage of static variable It makes your program  memory efficient  (i.e it saves memory). Understanding problem without static variable class  Student{         int  rollno;        String...

Access modifiers

access modifiers class Modifiers: Once we are writing a class the access modifier describes the properties of that class .(creation of child class is allowed or not ,creation of object is allowed or not ,we can access this class from outside the package or not and is accessing certain methods and variables of the class from outside is allowed). Access specifiers or Access modifiers are same in case of java.java compiler shows the error related to public,static,.......so on , it use the word modifier not Specified. The allowed modifiers for the Top level classes are   : 1 . public   2 . default   3.   final   4.abstract   5.   strictfp If we are using other then these modifiers ,compile time error saying modifier <some > not allowed here. For the inner classes the following are allowed modifiers: 1.public 2. private 3.protected 4.default 5.final 6.abstract 7.static 8.strictfp public class: A public class can be accessed ...