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

Explain the difference between private, public, package and protected in java?

807


What is defined as false sharing in the context of multithreading?

775


What is object of class in java?

836


What is data type modifier?

719


What is java virtual machine and how it is considered in context of java’s platform independent feature?

857


How can I become a good programmer?

692


How many wrapper classes are there in java?

767


How the interruptible method gets implemented?

747


What is meant by string is immutable?

735


What are the principle concepts of oops?

737


What are the concepts of 'OOPS'?

826


Can a static block throw exception?

862


How do I get 64 bit java?

720


What is * argv?

934


Give an example of use of pointers in java class.

764