Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Abstract type in java

  1. #1
    Junior Member vanshika's Avatar
    Join Date
    Apr 2013
    Location
    India
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Abstract type in java

    We have abstract classes as well as abstract method in java but why we do not have abstract variable in java??
    vanshika..


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Abstract type in java

    Can you give an example of why it would be useful?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member vanshika's Avatar
    Join Date
    Apr 2013
    Location
    India
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Abstract type in java

    The reason is same as abstract class and abstract method is useful.
    vanshika..

  4. #4
    Junior Member
    Join Date
    Jun 2013
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Abstract type in java

    Why is an abstract class or method useful? I've been trying to understand this for days!

  5. #5
    Member angstrem's Avatar
    Join Date
    Mar 2013
    Location
    Ukraine
    Posts
    200
    My Mood
    Happy
    Thanks
    9
    Thanked 31 Times in 29 Posts

    Default Re: Abstract type in java

    Interfaces are very similar to abstract classes, so I'll try to describe on an interface example.
    Consider List.
    Now consider ArrayList and LinkedList, they're implementations.
    It turns out, that this implementations have different performance and each is efficient in different situations. So it might be crucial for you to select the right one for your project.
    Now suppose, you're writing a project, who deals with lists extensively. And you have lots of methods, who take, say ArrayList as a parameter. Then suddenly you realize, that ArrayList is completely not what you want, that LinkedList would be right solution. What happens next is tedious process of changing signatures of lots of methods, changing their arguments from "ArrayList" to "LinkedList".
    Now imagine, that in the same project all the methods take List as arguments. What happens if you want to change implementation of a collection from ArrayList to LinkedList? Well, you might need to change a declaration of it from "new ArrayList<Foo>()" to "new LinkedList<Foo>()". But you don't have to change signatures of methods: methods don't care about implementation, they care about interface.
    So, as you see, the flexibility increases greatly.

  6. #6
    Junior Member
    Join Date
    Jun 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Abstract type in java

    abstract variable? funny name. You need to understand the definition of abstract class(similiar to virtual class in C++). The abstract class is for later implementation use in its inheritance classes. And it is could not initialzed at all. Simplely because it is not a 'complete' class. The usefulness for this kind of class is on its inheritance classes which could implement its abstract methods in its own purpose. that is the beauty of abstract class.

  7. #7
    Junior Member
    Join Date
    Jun 2013
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Abstract type in java

    I understand what you are saying. I'm just trying to figure out why I would use abstract classes in developing an application program. Can you give me a business example?

Similar Threads

  1. Java abstract/implements
    By maple1100 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: March 28th, 2013, 11:12 AM
  2. Java abstract
    By maple1100 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 25th, 2013, 08:33 PM
  3. [SOLVED] Abstract method in a non-abstract class
    By bassie in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 2nd, 2012, 11:27 AM
  4. GUI error: is not abstract and does not override abstract method
    By djl1990 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 21st, 2011, 01:26 PM
  5. abstract class & 'covariant' return type?
    By jezza10181 in forum Java Theory & Questions
    Replies: 2
    Last Post: August 12th, 2011, 02:26 PM