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) |
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; } }
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); } }
name : Peter age : 32 companyCode : 2000 salary : 50000To 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:
No comments:
Post a Comment