Go Back   Java Programming Forums > Java Standard Edition Programming Help > Object Oriented Programming


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 21-09-2009, 05:19 PM
Junior Member
 

Join Date: Sep 2009
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
kalees is on a distinguished road
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 :

Java Code
 interface testInteface{
public void calculation();
}
my doubt is after we extends the interface again we are creating method like

Java Code
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; 21-09-2009 at 05:22 PM. Reason: Make it clear queries....
Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 21-09-2009, 08:08 PM
helloworld922's Avatar
Super Moderator
 

Join Date: Jun 2009
Posts: 1,347
Thanks: 5
Thanked 285 Times in 257 Posts
helloworld922 will become famous soon enoughhelloworld922 will become famous soon enoughhelloworld922 will become famous soon enough
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).
__________________
ASCII a question .. Get an ANSI

Please surround your code with [highlight=Java]code goes here[/highlight].
Reply With Quote
  #3 (permalink)  
Old 22-09-2009, 07:38 AM
Json's Avatar
Super Moderator
 

Join Date: Jul 2009
Location: Manchester, United Kingdom
Posts: 1,190
Thanks: 57
Thanked 137 Times in 133 Posts
Json will become famous soon enoughJson will become famous soon enoughJson will become famous soon enough

I'm feeling Happy
Default Re: My doubt may be stupid

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

// Json
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
JComboBox doubt rajaramesh.tadi AWT / Java Swing 0 24-08-2009 01:18 PM
a doubt TARUN JORA Java Theory & Questions 2 15-05-2009 09:30 PM
Doubt About Socket sivakrish85 Java Networking 2 08-10-2008 04:03 AM


100 most searched terms
Search Cloud
2359-unable-move action listener in java actionlistener actionlistener in java addactionlistener addactionlister buffered read two integer value in java create an abstract class called shape with abstract methods+java double to integer double to integer in java double to integer java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space format double java get files from folder java by threads get mouse position java how to convert list to map in java how to format double in java how to format doubles in java http://www.javaprogrammingforums.com/collections-generics/2688-grade-array-trouble.html http://www.javaprogrammingforums.com/object-oriented-programming/3713-limiting-decimal-places-double.html infix to postfix in java iphone java java actionlistener java cos java deallocate java double format java double to int java font attributes java format double java forum java forums java get mouse position java programming codes using astirisks java programming forum java programming forums java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space jbutton actionlistener jbutton with key enter jtable questions in java jtext bold jtextfield output from formula jxl.read.biff.biffexception: unable to recognize ole stream kilowatts java program mean value decimal double java oops java assignments smack api messagelistener transaction using gui and 2 dimensional array code in java two dimensional arraylist in java

All times are GMT. The time now is 09:40 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.