Constructor Chaining
Constructor Chaining
Static Variables
class Employee
public class Test
{
{
int eid;
static int x = 100;
String name;
int y = 100;
static String company = "Studytonight";
public void increment()
{ {
x++; y++; int eid;
} String name;
public static void main( String[] args ) static String company_name;
{
Test t1 = new Test(); static {
Test t2 = new Test(); company_name ="StudyTonight";
t1.increment(); //static block invoked before main()
t2.increment(); method
System.out.println(t2.y); }
System.out.println(Test.x);
//accessed without any instance of class. public void show()
} {
} System.out.println(eid+" "+name+"
"+company_name);
Static Method in Java }
public static void main( String[] args )
{
A method can also be declared as static. ST_Employee se1 = new
Static methods do not need instance of its ST_Employee();
class for being accessed. main() method is se1.eid = 104;
the most common example of static se1.name = "Abhijit";
method. main() method is declared as se1.show();
static because it is called before any object }
of the class is created.
}
class Test
{
class ST_Employee