Solved

abstract class with all non abstract mentods

Posted on 2016-08-13
6
84 Views
Last Modified: 2016-08-14
Hi,
Can a abstract class with all non abstract mentods? Is that is possible. I am under impression that atleast one method of abstract class should be abstract. What are advantages and practical uses of abstract methods compared to interface. I see many cases abstract class is implements a interface. Then a concrete class extends the abstract class. I wonder what is use of this pattern

interface--->abstract class(implements)--->concrete class(extends)
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 27

Accepted Solution

by:
dpearson earned 250 total points
ID: 41755192
>> Can a abstract class with all non abstract methods?

Yes there's nothing wrong with that.  It's not common but it's allowed.

>> What are advantages and practical uses of abstract methods compared to interface.

Interfaces specify a list of methods with no implementations.
Abstract classes can include implementations (code) and fields (values).  So you can do more with an abstract class.

Why then not just use abstract classes everywhere?  Because a given concrete class can only inherit from at most 1 abstract class.  But it can implement as many interfaces as it wants.

So interfaces are more flexible.

Doug
0
 
LVL 10

Assisted Solution

by:Jeffrey Dake
Jeffrey Dake earned 250 total points
ID: 41755205
Doug is correct except that in the newest version of Java they have introduced the ability to but a default implementation of a method in an interface. This gives a little more flexibility in trying to do multi inheritance in a class.

Usually the benefit of interfaces is it really helps you if you are going to have multiple classes that need to have a common set of methods but don't entirely work the same.
0
 
LVL 7

Author Comment

by:gudii9
ID: 41755544
Doug is correct except that in the newest version of Java they have introduced the ability to but a default implementation of a method in an interface. This gives a little more flexibility in trying to do multi inheritance in a class.

any good links or examples on this?
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 27

Expert Comment

by:dpearson
ID: 41755591
Yeah I didn't mention default implementations as I'm concerned it may confuse your understanding if you're not clear on abstract classes vs interfaces yet.

But anywhere here's some info on them:
https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html

(Oracle added this capability so they could extend some existing interfaces in the Java language without breaking a ton of existing code).

Doug
0
 
LVL 7

Author Comment

by:gudii9
ID: 41755873
>> Can a abstract class with all non abstract methods?

Yes there's nothing wrong with that.  It's not common but it's allowed.

it is kind of defeating the purpose for which we create abstract class right?
if we do not have abstract methods in it it seems very uncommon to me.
0
 
LVL 10

Expert Comment

by:Jeffrey Dake
ID: 41755898
Not always, you may just have a whole bunches of functions you want inherited but don't want that base class to ever be instantioated.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question