purpose of static members

A member of a class may be delcared as static.

A static member, is associated with the class(in which it is delcared), and not with the indidvidual objects.
Since static members are associated with class, they can be directly accessed with class name.
static members can be accessed, even before creation of object of the class.

A data members declared as static has common storage and value for the class, i..e for all objects of the class.

From a non static method both static and non static data members and member methods can be used or invoked.
Where as from static method only static members can be used or invoked. So, to invoke non static methods, from a static method, we need to create object of class, whose method need to be invoked.

this keyword cannot be used in static methods, as both of them contradict. static is unrelated to object, where as this refers to current object.

static example

//Example of static keyword
class Abcd
{
	static public int i;
	//i value is common to all object of Abcd
	//static members are associated with class, and not with object

	int j;
	//each object of Abcd, can have different value of j


	public int getI()
	{
	return i;
	}

	public int getJ()
	{
	stTest();
	return j;
	}

	//static data members/methods can be used in non static methods
	//but a static method can refer only static methods or data members
	public static void stTest()
	{

	System.out.println("This is static method");
	//j = 10; //error, only static variables can be referenced
	}
}

public class StaticExample {

	float met1()
	{
	return 0.0f;
	}

	public static void main(String args[])
	{
	Abcd.i = 50;

	//Abcd.j = 20;
	//Compile error, j cannot be accessed directly with class name
	//because j is non static

	StaticExample se = new StaticExample();
	se.met1();

	Abcd.stTest();

	Abcd obj = new Abcd();
	//obj.j = 34;
	//obj.i = 20;

	System.out.println("Abcd.i is "+Abcd.i);
	System.out.println("obj.j is "+obj.j);
	}
}

You may also like to read:
this keyword
How to declare static block
Are static constructors possible?
purpose of static method in abstract class

static method in Abstract class

Can a static method be a member of Abstract Class?

Read here for What is a abstract method? and what is abstract class?

static method is associated with class and not with individual objects of the class.

Yes, an abstract class can have static methods. But a static method cannot be abstract.

Also remember that, static methods take part in inheritance.
But static methods do not take part in polymorphism.

Below example shows that an abstract class, can have static method.


abstract class Abs1{
	int i,j;
	Abs1(){
		super();
		System.out.println("Abs1() Constructor");
	}

	Abs1(int i, int j)
	{
		this();
		this.i = i;
		this.j = j;
		System.out.println("Abs1(int i, int j) Constructor");
	}

	public static void met1()
	{
		System.out.println("met1() method in Abs1 class");
	}
}

public class AbstractDemo extends Abs1{

	AbstractDemo(){
		System.out.println("AbstractDemo() Constructor");
	}
	public static void main(String args[])
	{
		AbstractDemo obj = new AbstractDemo();
		System.out.println("in main() method");

		Abs1.met1();
	}
}

You may also like to read:
Difference between static and non static block
how many keywords or reserved words in java
purpose of static inner class

What is purpose of constructors in Abstract classes?

Abstract class is a class, which cannot be directly instantiated. Abstract class may or may not have abstract methods. A class can be declared abstract, by specifying abstract keyword.

An abstract method is a method, whose declaration is provided in abstract class, and this method’s definition is provided by any of the Derived class.

As known, an abstract class cannot be instantiated, i..e object of an abstract class cannot be created, directly.

In any class, Constructor just initializes data members, and does not create an object.
Similarly Constructor in Abstract class does not create an object, and just initializes data members.

Also, note that
1. Constructor cannot be abstract.
2. super(), this() and this. can be used in abstract classes, as shown in below example.

abstract class Abs1{
	int i,j;
	Abs1(){
		System.out.println("Abs1() Constructor");
	}

	Abs1(int i, int j)
	{
		this();
		this.i = i;
		this.j = j;
		System.out.println("Abs1(int i, int j) Constructor");
	}
}

public class AbstractDemo extends Abs1{

	AbstractDemo(){
		System.out.println("AbstractDemo() Constructor");
	}
	public static void main(String args[])
	{
		AbstractDemo obj = new AbstractDemo();
		System.out.println("in main() method");
	}
}

Output:
Abs1() Constructor
AbstractDemo() Constructor
in main() method

Below is an example in which a derived class from an abstract class, is also abstract

package p1;

abstract class A1{
	public void met1(){
		System.out.println("met1() in A1");
	}

	static void test()
	{
		System.out.println("test()");
	}

	abstract public void met2();

	abstract public void met3();
}


//class B1 need to be declared abstract as it does not implement met3() of A1 class
abstract class B1 extends A1{
	public void met2()
	{
		System.out.println("met2() in B1");
	}
}

class C1 extends B1{
	public void met3()
	{
		System.out.println("met3() in C1");
	}
}

public class AbstractDemo {
	public static void main(String[] args) {
		C1 obj = new C1();

		obj.met1();
		obj.met2();
		obj.met3();

		A1.test();
	}
}

Below is an example in which an abstract class implements an interface.


interface MyAbc
{
	//constants can be declared in interface
	final int CHECK = 1;

	public void met1();

	public void met2();
}

abstract class X1 implements MyAbc
{

	public void met2(){
		System.out.println("met2() implemented in X1");
	}

	abstract public double myMet();
}

class Y1 extends X1
{
	public void met1()
	{
		System.out.println("met1() implemented in Y1");
	}

	public double myMet()
	{
		System.out.println("myMet() implemented in Y1");

		return 0.0;
	}
}

public class AbstractAndInterface {
	public static void main(String args[])
	{
		Y oy = new Y();

		oy.met1();
		oy.met2();

		System.out.println(MyAbc.CHECK);
	}
}

You may also like to read:
What is purpose of this keyword in Java
What is the purpose of super keyword in java