• Post Reply Bookmark Topic Watch Topic
  • New Topic

Abstract classes  RSS feed

 
Matthew Filippone
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What programs use abstract classes? Please let me know. Thanks.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lots do. Whenever you have an inheritance hierarchy where you don't need to instantiate every class. I think you will find just about every Swing app does. Look at the inheritance heirarchy for JFrame for example. Component is abstract, and there are many methods which take a Component. You usually pass a concrete instance, however.
 
Matthew Filippone
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would be an example of a program though? Like netbeans?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NetBeans is a big piece of software, it undoubtedly uses abstract classes somewhere. Probably any large project has some use for abstract classes somewhere.

What exactly do you hope to learn from the answer to this question? Are you asking this because you want to know what abstract classes are useful for?

They are sometimes useful for implementing common code that is necessary in different concrete (= non-abstract) subclasses - so that you don't have to copy and paste those methods in multiple classes. (Copy & paste programming is a really bad practice).
 
Matthew Filippone
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would just like to learn what are the variety of programs that use it? Is there a simple program out there that uses it?
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write one.

What about some cars vans and buses? You will probably need an abstract Vehicle class.
 
Matthew Filippone
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it better to use interfacing than abstract classes?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Filippone wrote:I would just like to learn what are the variety of programs that use it? Is there a simple program out there that uses it?

Abstract classes is just one of the many features of the Java programming language. Probably many programs use this feature. But your questions is a little bit strange. You'd only know if you would look at all the source code of all those programs. It's a bit like asking "Can you give me a list of books in which the word 'coffeepot' appears?".

If you want to learn more about abstract classes, then have a look at this page in Oracle's Java Tutorials: Abstract Methods and Classes.

We also have a frequently asked questions page: Interface vs abstract class.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interfaces define a contract that a class must adhere to. This is usually related to the behavior of a class.

Abstract classes are a placeholder for common functionality that subclasses will have.

Refer to the link Jesper has provided for more info.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An abstract Vehicle class would have implemented methods like start() stop() turnRight() turnLeft() etc. It would not have methods like sellTicket() which would belong to the Bus class.

Interfaces only have non‑static unimplemented methods. That is absolutely immutably inviolably true … until you install Java8
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!