diff between abstract methods and interfaces with programing
(code) example?
Answer Posted / karthik
abstract class A
{
protected abstract void show();
}
public class xx extends A
{
protected void show()
{
System.out.println("karthik ok");
}
static void main(String aa[])
{
xx ob=new xx();
ob.show();
}
}
But in Interface
interface A
{
protected abstract void show();
}
public class xx implements A
{
protected void show()
{
System.out.println("karthik ok");
}
static void main(String aa[])
{
xx ob=new xx();
ob.show();
}
}
modifier protected not allowed here
protected abstract void show(); in Interface
Because Default public method
But in Abstract class we can have protected
interface A
{
int x;//Error we should need initial value
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Can substring create new object?
what is meant by encapsulation?
Can a class be private in java?
Can we sort list in java?
Why do we need hashset in java?
What are the differences between checked exception and unchecked exception?
Why are lists ordered in java?
Why do we use predicate in java?
What is meant by oops concept in java?
How will you print number in reverse (descending) order in BST.
What state is a thread in when it is executing?
Differentiate storage classes on the basis of their scope?
What is sortedmap in java?
What is the function of java?
What is boolean false?