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 |
is it possible to add a object in a HASHMAP
what is associative array
What do u mean by wrapper Class? What do u mean by Jvm... How do u change JVM for other OS? Or No need to Change ...? its like tricky
i need to know the website that i can compile and run a java code in online.(while system doesn't contain any jdk and jre)
How to re-get an object that is collected by garbage collector?
what is thread in Java ?
Can a class have an interface?
Can we override private methods?
What is arguments in java?
How to access a method that it declared as protected?
What is consumer in java?
Which One is optimal to choose ? Syncronized hash map or Hash table with single thread model? How can a hash map syncronized with out using syncrozed blocks in programm?