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 3 of 3

Thread: My doubt may be stupid

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation My doubt may be stupid

    Hi!

    I having a stupid doubt....Sorry for asking ths....

    when we creating Interface or abstract class we defining method,after that
    we extends ths interface or abstract class to other class.....
    for eg :

     interface testInteface{
    public void calculation();
    }

    my doubt is after we extends the interface again we are creating method like

    class exampleClass implements testInteface{
    public void calculation() {          // this called overriding method from interface... but it seems like we creating                                                                          
                                                         method once again what is the advantage of having interface  
    }
    }

    hope u understand my doubt,I don't have a basic knowledge of java,....i am having this doubt from the begging
    help me out.............

    Thanks,

    Kalees
    Last edited by kalees; September 21st, 2009 at 12:22 PM. Reason: Make it clear queries....


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: My doubt may be stupid

    In a sense, yes you are over-riding the method. However, that's the point. The method defined in the interface does nothing, but it allows someone who wants to use that interface to know what they can expect to give as input and what to expect as output.

    Ex: say we have an interface that's called Drivable, which inside has the methods turnLeft and turnRight. Then, we have several classes that implement Drivable: Civic, Bike, Fararri. The Drivable interface methods by themselves don't mean anything (makes sense, what are you driving?), but in each implementing class, they MUST implement the turnLeft/turnRight methods to be Drivable.

    The same idea applies to abstract classes. Take the abstract class Shape. Inside, let's pretend we have an abstract method called area. What is the area of a shape? It's inherently undefined. However, if we have a class Square that inherits from Shape, it must implement the area method (or, be declared an abstract class, but that doesn't make much sense here).

  3. #3
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: My doubt may be stupid

    See http://www.javaprogrammingforums.com...hod-calls.html on a simple usage of interfaces.

    // Json

Similar Threads

  1. JComboBox doubt
    By rajaramesh.tadi in forum AWT / Java Swing
    Replies: 0
    Last Post: August 24th, 2009, 08:18 AM
  2. Which javadoc tag is used to denote a comment for a method parameter?
    By TARUN JORA in forum Java Theory & Questions
    Replies: 2
    Last Post: May 15th, 2009, 04:30 PM
  3. Replies: 2
    Last Post: October 7th, 2008, 11:03 PM