what is difference between interface and abstract class..?
Answer Posted / nipun advinder
Interface:
1)In interface you cannot provide any implementations of
any function.
2)you must give implementations for all the methods of an
interface if you implement it in a class
3)cannot have private method
4)Scenario to use it would be to separate out the
implementation from the api
Abstract Class:
1)In interface you can provide implementations of any
function but at least one function should be abstract.
2)you must give implementations for all the abstract
methods of a abstract class if you extend it in a class
3)can have private method
4)Scenario to use it would be to denote is as a generalized
class which could provide some common functionality and you
want that it cannot be instantiated instead more
specialized forms are used.
eg abstract class account
class savingsaccount extends account
class currentaccount extends account
In this scenario assume that class account cannot provide
the complete functionality alone but contain some standard
ones.
| Is This Answer Correct ? | 3 Yes | 1 No |
Post New Answer View All Answers
Which collection is thread safe in java?
What is prefix of a string?
What are the advantages of assembly language?
How to make a non daemon thread as daemon?
What is the difference between a loader and a compiler?
What is runtime locatable code?
Can we sort arraylist in java?
Break statement can be used as labels in java?
Define a java class.
You can create a string object as string str = “abc”; why cant a button object be created as button bt = “abc”;? Explain
Explain the importance of throwable class and its methods?
public class Test { public static void main(String[] args) { int countA = 0; int countB = 0; int countC = 0; int countD = 0; int countE = 0; int countF = 0; int countG = 0; int countH = 0; int countI = 0; int countJ = 0; int countK = 0; int countL = 0; int countM = 0; int countN = 0; int countO = 0; int countP = 0; int countQ = 0; int countR = 0; int countS = 0; int countT = 0; int countU = 0; int countV = 0; int countW = 0; int countX = 0; int countY = 0; int countZ = 0; } } Can anybody tell me any alternate solution(like loop or something) to automate this initialization process. Ex:- for(char chr='A';chr<='Z'; chr++) { (int) String "count"+chr = 0; }
What is the point of polymorphism java?
What comes to mind when someone mentions a shallow copy in java?
When can an object reference be cast to an interface reference in java programming?