Tuesday 15 September 2015

Java Tutorial : Java Static Variable


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 
Student.java
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("**********************");
    }
}
StudentDemo.java
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();
    }

}
Output
name : John
age : 6
SchoolCode : 5000
**********************
name : Dave
age : 7
SchoolCode : 5000
**********************
name : juli
age : 5
SchoolCode : 5000
**********************
To Download VariableDemoStaticApp Project Click the below link
https://sites.google.com/site/javaee4321/java/VariableDemoStaticApp.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