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

Why string is immutable or final in java

0 Answers  


how can i kill thread without stop() and destroy()

1 Answers  


What are different ways of object creation in java ?

0 Answers  


Can a lock be acquired on a class?

3 Answers  


Why main() method is public, static and void in java ?

0 Answers  


What is output buffer?

0 Answers  


what is inner class?

6 Answers   HCL,


What's the purpose of using break in each case of switch statement?

0 Answers  


Can we declare the static variables and methods in an abstract class?

0 Answers  


Can you override static method in java?

1 Answers  


How many characters is 16 bytes?

0 Answers  


I declared main() method as private. But it still running and displaying the output. Please Answer it . Code Snippet as Below: import java.io.*; class over { private static void main(String[] args) { int high = Integer.MAX_VALUE; int overflow = high + 1; int low = Integer.MIN_VALUE; int underflow = low - 1; System.out.println(high + "\n" +overflow +"\n"+ low +"\n"+underflow); //System.out.println(overflow); //System.out.println(low); //System.out.println(underflow); } }

4 Answers   Cap Gemini,


Categories