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

Is string a keyword in java?

1 Answers  


Can we create an object of static class in java?

0 Answers  


What is string substring?

0 Answers  


Why const and goto are reserved keyword in java?

1 Answers  


If try block is successfully executed, Then Is Finally block executed?

0 Answers   PUCIT,






How use .contains in java?

0 Answers  


How does a try statement determine which catch clause should be used to handle an exception?

2 Answers  


Can we able to pass objects as an arguments in java?

0 Answers  


Why put method is used?

0 Answers  


explain local datetime api in java8?

0 Answers  


WHAT IS MARKER INTERFACE,AND NO METHODS IS NOT THERE ON THAT INTERFACE THEN WHY WE USED IN JAVA?

3 Answers   L&T,


What is the main use of java?

0 Answers  


Categories