Usage of abstract class and interface

0 votes

I am really confused about when are the abstract classes or interfaces are created? And how do I decide which one to use and when?

Oct 23, 2018 in Java by code.reaper12
• 3,450 points
98 views

1 answer to this question.

0 votes

Well let me draw a clear line between the two:

InterfaceAn interface is used to declare the mandatory class members and methods required in a class. Classes implementing this interface then can declare and implement the methods of this interface according to their need. Also, you can implement any number of interfaces as you want.

Abstract Class: An abstract class is used generally to obtain a default implementation. Classes extending an abstract class needs to implement just its abstract methods and members. Unlike interfaces, you can extend only one abstract class at a time.

answered Oct 23, 2018 by geek.erkami
• 2,640 points

Related Questions In Java

0 votes
1 answer

Behavior of Integer Wrapper class and == operator

Well, this is happening because of the ...READ MORE

answered Jun 6, 2018 in Java by v.liyyah
• 1,300 points
541 views
0 votes
2 answers

What is the use of toString method in Java and how can I use it ?

Whenever you require to explore the constructor ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,050 points
803 views
0 votes
1 answer

In which class is the "length" property of array defined ?

It's defined in the Java language specification: The members ...READ MORE

answered May 8, 2018 in Java by Rishabh
• 3,540 points
43 views
+1 vote
3 answers

Copy Java Array and make a duplicate of it

int[] a = {1,2,3,4,5}; int[] b = Arrays.copyOf(a, ...READ MORE

answered Aug 30, 2018 in Java by Sushmita
• 6,880 points
114 views
0 votes
2 answers

What is the difference between implements and extends?

Extends : This is used to get attributes ...READ MORE

answered Aug 3, 2018 in Java by samarth295
• 2,190 points
616 views
0 votes
1 answer

Can Abstract Class have a Constructor?

Yes, an abstract class can have a ...READ MORE

answered May 11, 2018 in Java by sharth
• 3,350 points
97 views
0 votes
1 answer

using comparator for sorting in java

You've got two problems: 1) You're using Collections.sort (which takes ...READ MORE

answered Jul 6, 2018 in Java by samarth295
• 2,190 points
64 views
0 votes
1 answer

What is abstract class in java?

A class that is declared with abstract ...READ MORE

answered Jun 11, 2018 in Java by Daisy
• 8,050 points
149 views
0 votes
2 answers

Listing all the subclasses of a specific class in Java

This is not possible to do using ...READ MORE

answered Aug 21 in Java by Sirajul
• 37,080 points
339 views
0 votes
1 answer

Difference between String.equals() and ==

Though both are used for comparison, but the ...READ MORE

answered May 7, 2018 in Java by geek.erkami
• 2,640 points
34 views