Click here to watch in Youtube :
https://www.youtube.com/watch?v=mfao9NrOBos&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java Static Variable |
public class Student { String name; // instance variable int age; // instance variable static int SchoolCode = 1000; // Static Variable void printInstanceAndStaticVariables() { System.out.println("name : "+ name); System.out.println("age : "+ age); System.out.println("SchoolCode : "+ SchoolCode); System.out.println("**********************"); } }
public class StudentDemo { public static void main(String[] args) { Student john = new Student(); john.name = "John"; john.age = 6; john.SchoolCode = 2000; Student dave = new Student(); dave.name = "Dave"; dave.age = 7; dave.SchoolCode = 3000; Student juli = new Student(); juli.name = "juli"; juli.age = 5; juli.SchoolCode = 5000; john.printInstanceAndStaticVariables(); dave.printInstanceAndStaticVariables(); juli.printInstanceAndStaticVariables(); } }
name : John age : 6 SchoolCode : 5000 ********************** name : Dave age : 7 SchoolCode : 5000 ********************** name : juli age : 5 SchoolCode : 5000 **********************
https://sites.google.com/site/javaee4321/java/VariableDemoStaticApp.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment