Tuesday 15 September 2015

Java Tutorial : Java Variables (Local Variables, Instance Variables, Static Variables)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=1_bRQ-Ypv6E&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java Variables (Local Variables, Instance Variables, Static Variables) 
Java Tutorial : Java Variables (Local Variables, Instance Variables, Static Variables) 
Java Tutorial : Java Variables (Local Variables, Instance Variables, Static Variables) 
Java Tutorial : Java Variables (Local Variables, Instance Variables, Static Variables) 
Employee.java
public class Employee
{
    String name; // instance variable
    int age; // instance variable

    static int companyCode = 2000; // static variable

    public int getSalary()
    {
        int salary = 60000; // local variable
        int tax = 10000; // local variable
        salary = salary - tax;
        return salary;
    }

}
EmployeeDemo.java
public class EmployeeDemo
{

    public static void main(String[] args)
    {
        Employee employeeObj = new Employee();
        
        /*
         *  Accessing the instance variable's name and age.
         */
        employeeObj.name = "Peter";
        employeeObj.age = 32;
        
        System.out.println("name : "+employeeObj.name);
        System.out.println("age : "+employeeObj.age);
        

        /*
         *  Accessing the static variable companyCode.
         */
        System.out.println("companyCode : "+Employee.companyCode);
        
        int salary = employeeObj.getSalary();
        System.out.println("salary : "+salary);

    }

}
Output
name : Peter
age : 32
companyCode : 2000
salary : 50000
To Download VariableDemoLocal-Instance-Static-App Project Click the below link
https://sites.google.com/site/javaee4321/java/VariableDemoLocal-Instance-Static-App.zip?attredirects=0&d=1

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment