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
How do you stop a thread in java?
What does the ‘static’ keyword mean? Is it possible to override private or static method in java?
Explain what access modifiers can be used for variables?
Write a function for palindrome and factorial and explain?
which pattern is default in scanner package?
What is the purpose of the System class?
Can singleton class be inherited in java?
Is void a return type?
how to know the total memory occupied by the objects in the ArrayList(Array list may contain duplicate objects)
What is the difference between inheritance and encapsulation?
What is a generic code?
What are the advantages and disadvantages of object cloning?
Why runnable interface is used in java?
What is the access scope of a protected method?
What does provide mean construction?