diff between abstract methods and interfaces with programing
(code) example?
Answers were Sorted based on User's Feedback
Answer / naresh p
an abstract class contains the concrete methods as well
abstract methods. It may instance variables and static
final variables
an interface contains only abstract methods. all the
variables are by default static and final.
an abstract class contains constructor where as an
interface does not have constructors...
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / 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 |
Any one can explain how the inerface uses in java. give with example.
How many bytes is a unicode character?
What is a method ?
What are the performance implications of interfaces over abstract classes?
What does n mean in java?
What are interfaces?
What is serialversionuid?
Can u write constructor in abstract.If yes den when it will be invoked.
what is unreachable code problem in multiple catch statements
I have a class which is abstract which contains only the abstract methods. This is similar to an interface. Then, if i have given a choice to choose one of them. Which one i have to choose and why?
Why is inheritance used in java?
Why are getters and setters used?