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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What happens when heap memory is full?

528


enlist some features of jdk.

562


How many types of classes are there in java?

523


What is an example of declaration?

528


Differentiate between array list and vector in java.

639






Can we cast any other type to boolean type with type casting?

543


What is foreach loop in java?

537


What causes memory leak in java?

484


Justify your answer that you can't define a method inside another method in java, if you can then how?

606


What are the advantages of compiled language?

578


What is generics in java interview questions?

542


Can constructor be protected in java?

513


How can we make sure main() is the last thread to finish in java program?

675


How do you replace all in word?

533


How do you check if two strings are equal in java?

589