From e7c72630c9e5e0fa8cc311ece87b683319d11c10 Mon Sep 17 00:00:00 2001 From: prathamjn26 <52950832+prathamjn26@users.noreply.github.com> Date: Wed, 16 Oct 2019 14:35:30 +0530 Subject: [PATCH] Create static_keyword_use --- Java/static_keyword_use | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Java/static_keyword_use diff --git a/Java/static_keyword_use b/Java/static_keyword_use new file mode 100644 index 0000000..9b13bb1 --- /dev/null +++ b/Java/static_keyword_use @@ -0,0 +1,31 @@ +//Java Program to demonstrate the use of static variable +class Student +{ + int rollno;//instance variable + String name; + static String college ="ITS";//static variable + //constructor + Student(int r, String n){ + rollno = r; + name = n; + } + //method to display the values + void display () + { + System.out.println(rollno+" "+name+" "+college); + } +} + +//Test class to show the values of objects +public class TestStaticVariable1 +{ + public static void main(String args[]) + { + Student s1 = new Student(111,"Karan"); + Student s2 = new Student(222,"Aryan"); + //we can change the college of all objects by the single line of code + //Student.college="BBDIT"; + s1.display(); + s2.display(); + } +}