Abstract class and Interface related of same methods we are extednind in class...... [modified]
-
Hi all, This is simple thinking concept query is that-I've an one abstract class that contain some method test() and i've one interface in that with same signature of abstract class method test() name ok fine.(they are just declared) now i want to implement in one class. And i called and provided some functionalities to the 2 methods, 1 is from abstract class and 1 is from interface . so how to call particular interface method with the class object that we are implemented in the class and how to call abstract class method with the class object.- bcoz are 2 same named methods and with the signature also same..........so how would know when we are declared object for class and calling some obj.test()-which method will displayed-is it from abstract or interface belonged method. can u plz give me reply very soon............
modified on Thursday, October 9, 2008 2:50 AM
-
Hi all, This is simple thinking concept query is that-I've an one abstract class that contain some method test() and i've one interface in that with same signature of abstract class method test() name ok fine.(they are just declared) now i want to implement in one class. And i called and provided some functionalities to the 2 methods, 1 is from abstract class and 1 is from interface . so how to call particular interface method with the class object that we are implemented in the class and how to call abstract class method with the class object.- bcoz are 2 same named methods and with the signature also same..........so how would know when we are declared object for class and calling some obj.test()-which method will displayed-is it from abstract or interface belonged method. can u plz give me reply very soon............
modified on Thursday, October 9, 2008 2:50 AM
-
Quick answer: Interfaces do not have implementations, classes do. So you don't have two different methods.
The need to optimize rises from a bad design
I mean that interface has only signature method that method name test(),similarly abstract class has same method test() with same signature of interface.That 2 methods are just declared. Now in my class i provided functionalities for those methods by inheriting both abstract and interface. Up to this okey ,now i declared one object for class calling method test() with that object.........so which method will be called ........either abstract class method or interface method. and why do u get that
-
I mean that interface has only signature method that method name test(),similarly abstract class has same method test() with same signature of interface.That 2 methods are just declared. Now in my class i provided functionalities for those methods by inheriting both abstract and interface. Up to this okey ,now i declared one object for class calling method test() with that object.........so which method will be called ........either abstract class method or interface method. and why do u get that
Okay, Few things: You inherit from abstract class, meaning you get some functionality. You don't inherit from interface, you implement it. This means, that when you implement an interface, you must write the implementation logic for the method defined in an interface. In your situation, the abstract class may create the implementation for the interface or if the abstract class doesn't do that, you must do it in inherited class Mika
The need to optimize rises from a bad design
-
Okay, Few things: You inherit from abstract class, meaning you get some functionality. You don't inherit from interface, you implement it. This means, that when you implement an interface, you must write the implementation logic for the method defined in an interface. In your situation, the abstract class may create the implementation for the interface or if the abstract class doesn't do that, you must do it in inherited class Mika
The need to optimize rises from a bad design
Sorry u could n't get my question. First i want to inheritance and implements methods of abstract class and interface(But here the 2 one is abstract class contain test() method,other one interface contain test() method. both are same in signature.) so I did inheritance and implementation for abstract class and interface in the class.Up to here fine...when declare a object for class and calling test() method with the class object so which of method will be called in the class ,either from implemented interface method or abstract class method.Bcoz they have same signature of two methods that is why am asking.
-
Sorry u could n't get my question. First i want to inheritance and implements methods of abstract class and interface(But here the 2 one is abstract class contain test() method,other one interface contain test() method. both are same in signature.) so I did inheritance and implementation for abstract class and interface in the class.Up to here fine...when declare a object for class and calling test() method with the class object so which of method will be called in the class ,either from implemented interface method or abstract class method.Bcoz they have same signature of two methods that is why am asking.