Class name.static data member name
static datatype x, y, z, .... ;
- public class Employee
- {
- static String cname;
- public static void main (String args[])
- {
- System.out.println(cname);
- Employee.cname="HCL";
- System.out.println(Employee.cname);
- }
- }
- To Compile - javac employee.java
- To Run - java Employee
- Result - null
HCL
Objname.instance data member name
datatype x, y, z, .... ;
- public class Employee
- {
- static String cname="HCL";
- String ename;
- public static void main (String ...a)
- {
- Employee e1 = new Employee();
- Employee e2 = new Employee();
- e1.ename="Uves";
- System.out.println(cname);
- System.out.println(e1.ename);
- System.out.println(e2.ename);
- }
- }
- To Compile - javac employee.java
- To Run - java Employee
- Result - HCL
Uves
null
| Copyright ©2016 | All Rights Reserved |
| Design by Uves Khan |