diff between abstract methods and interfaces with programing
(code) example?

Answers were Sorted based on User's Feedback



diff between abstract methods and interfaces with programing (code) example?..

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

diff between abstract methods and interfaces with programing (code) example?..

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

Post New Answer

More Core Java Interview Questions

What is a double?

0 Answers  


What is a line break example?

0 Answers  


We can write any Java Logics in our JSP. Then why we are using servlets(Controller Layer) to interact with the DAO ?

6 Answers   TCS,


Given: 1. package test; 2. 3. class Target { 4. public String name = “hello”; 5. } What can directly access and change the value of the variable name? 1 any class 2 only the Target class 3 any class in the test package 4 any class that extends Target

7 Answers   Infosys, WW,


suppose in a class there is a code like this: { Set hs=new Hashset(); hs.add(new Emp("kathy",1000)); hs.add(new Emp("kathy",2000)); } how can u avoid the above code in your class as set won't allow duplicate objects?

3 Answers  






What is __ init __ functions?

0 Answers  


How to implement Singleton

6 Answers   DELL,


How do you end a program?

0 Answers  


What is an association?

0 Answers  


How to convert a string to long?

2 Answers  


What is meant by local variable and instance variable?

0 Answers  


Explain wrapper classes in java?

0 Answers  


Categories