Difference between Abstract Class and Interface

Here is a fresher in Java. Could any body tell me the difference between Abstract Class and Interface. And suppose Abstract class has three methods, in those, two of them are Abstract and one is normal method, and it has been implemented in that class itself. If we extend the Abstract class to our class, do we need to over ride or implement all the methods that are there in the Abstract class or we need to implement only those methods that have been declared as abstract. If it is so, then what is the purpose of implementing non abstract method in the Abstract class.

Sravan

[592 byte] By [ksravan_kumara] at [2007-9-29 19:36:29]
# 1

public abstract class TestAbstract {

public abstract void method1();

public abstract void method2();

public static void method3() {

// non-abstract method must have a body

}

}

public class TestAbstract2 extends TestAbstract {

public void method1() {

// Does not work:

// Object test = new TestAbstract();

TestAbstract.method3();

}

public void method2() {

}

}

- you will have to implement all method which are declared as abstract. you do not need to implement method3 in this example., only method1 and method2.

- an abstract class cannot be instantiated (doesn't work: Object test=new MyAbstractClass())

- a non-abstract method in an abstract class can be used, if it's a static member.

- with "extends" you can only have one class, and your class will inherit the members of the superclass

- with "implements" you can use multiple interfaces, which are only a description of what you have to write yourself...

hamstaa at 2007-7-15 21:01:08 > top of Java-index,Security,Signed Applets...