Difference between interface and abstract class with ex.

Answer Posted / vinoth sing

abstract class contain both abstract and non abstract methods
vs
interface can have only abstract methods.

a class implementing a interface itself a abstract class.

eg for interface

interface shape2d
{
double getArea();
}

class circle implements shape2d
{
int radius;
public double getArea()
{
return math.pi*r*r;

}
circle(int radius)
{
this.radius=radius;
}
class circledemo
{

public static void main (string args[])
{
circle c= new circle(10);
system.out.println(c.getArea());
}

}

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between length and length() method in java?

880


Is java hard to learn?

713


What is a boolean structure?

807


What do you understand by synchronization?

815


What are thread local variables?

794


How do you pass by reference?

773


What is the meaning of 3 dots in java?

899


Can singleton class be serialized?

743


Can we define static methods inside interface?

750


How can we make string upper case or lower case?

800


What does singleton class mean?

742


How to sort list of list in java?

885


What is pre increment and post increment in java?

727


Can we override the private methods?

763


What is jdbc api?

770