import java.lang.System;
import java.lang.String;
class FirstApp
{
static int a =100;
float b = 7.9f; //always use f constant with float values else you will get CTE
static double d = 89.98;
public static void main(String[] args)
{ FirstApp f= new FirstApp();
//STATIC variables can be Accessed in three ways, Recommed way using CLASS name.
System.out.println("Ashutosh "+ a); //DIRECT access
System.out.println("Ashutosh "+ FirstApp.a); //using CLASS NAME, RECOMMEDED way
System.out.println("Ashutosh "+ f.a); // using OBJECT REFERENCE VARIABLE
System.out.println(f.b);
System.out.println(d);
//System.out.println(f.b);
}
}
Thanks
Happy programming!
import java.lang.String;
class FirstApp
{
static int a =100;
float b = 7.9f; //always use f constant with float values else you will get CTE
static double d = 89.98;
public static void main(String[] args)
{ FirstApp f= new FirstApp();
//STATIC variables can be Accessed in three ways, Recommed way using CLASS name.
System.out.println("Ashutosh "+ a); //DIRECT access
System.out.println("Ashutosh "+ FirstApp.a); //using CLASS NAME, RECOMMEDED way
System.out.println("Ashutosh "+ f.a); // using OBJECT REFERENCE VARIABLE
System.out.println(f.b);
System.out.println(d);
//System.out.println(f.b);
}
}
Thanks
Happy programming!
No comments:
Post a Comment