LEC : 20 | JAVA
LEC:20
Static Keyword in JAVA
Static Block | Static Method | Static Variable
Relation Between Static/Constructor/Main
Source Code:
package oops;
import java.util.Scanner;
class Student {
public
static String college="BPIT";
// int roll;
// int marks;
// static String change()
// {
// System.out.println("Enter College name : ");
// Scanner O1=new Scanner(System.in);
// college=O1.nextLine();
// System.out.println("College name is : "+college);
// return college;
// }
// void get()
// {
// System.out.println("roll : "+roll+"\tmarks : "+marks+"\tCollege is : "+college);
// }
//
// void set()
// {
// System.out.println("Enter roll and marks of the Student :");
// Scanner O1=new Scanner(System.in);
// roll=O1.nextInt();
// marks=O1.nextInt();
// }
static{
college="GGSIPU";
System.out.println("Here i am static");
}
// static{
// System.out.println("Here i am static block number 2");
// }
Student() {
System.out.println("Here I am Default Constructor");
}
}
public class OOPS {
public static void main(String[] args) {
// Student O2=new Student();
// O2.set(); O2.get();
//
// Student O3=new Student();
// O3.set(); O3.get();
//
Student O4=new Student();
// O4.set(); O4.get();
System.out.println("Here i am main class "+Student.college);
//Student.change();
}
}
Comments
Post a Comment