The program shows basic functionality of java class, object, and the static variable.

Program Code:
class Student
{
String name, city;
int age;
static int m;
void printData()
{
System.out.println(“Student name = “+name);
System.out.println(“Student city = “+city);
System.out.println(“Student age = “+age);
}
}
class Cs
{
public static void main(String args[])
{
Student s1=new Student();
Student s2=new Student();
s1.name=”Amit”;
s1.city=”Dehradun”;
s1.age=22;
s2.name=”Kapil”;
s2.city=”Delhi”;
s2.age=23;
s2.printData();
s1.printData();
s1.m=20;
s2.m=22;
Student.m=27;
System.out.println(“s1.m = “+s1.m);
System.out.println(“s2.m = “+s2.m);
System.out.println(“Student.m = “+Student.m);
}
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: