Extending and implementing

Is there a way to tell the compiler: this variable is of this class and implements that interface.
Say for instance a Component that implements ActionListener
extending component with an abstract class that implements ActionListener and then extend this class wouldn't work since then i can'T as well extend button textArea ect.

if(variable instanceof Component) {
//do something
if(variable instanceof ActionListener) {
//do something else
if( (variable instanceof Component) &&
(variable instanceof ActionListener) ) {
// really do something else
}

Similar Messages

  • Difference between extends and implements

    hi
    i am new to java. i need to know the difference between extends class implement class.
    can anybody explain in simple words? i am new too oops concept also?
    what are the conditions to use extends class, implement and interface?
    class b extends a implements c
    i know class a is a super class and class b is a sub class.
    if class b extends class a means how should be the class a, what about the methods?
    and class a implements class c means what should be the conditions?
    i searched in Internet but the explanation is not very to me.can body explain me please?
    thank you

    sarcasteak wrote:
    Your class can implement an interface, which means it must use the methods defined in the interface.No, it doesn't need to use them. It needs to implement them. Or be declared abstract.
    Note that the methods in the interface are empty,No, they're not. They're abstract.
    // empty method
    void foo() {}
    // abstract method
    abstract void foo();(The abstract keyword is optional for interface methods, since they're all abstract.
    and you have to define what they do in your class that implements the interface.Just like they have to for abstract methods in a class you extend, if the child class is not declared abstract.
    There really isn't any difference between "extends" and "implements." There is no situation where you can choose. Any case where one is legal, only that one is legal. They could just as easily be a single keyword.
    Presumably the OP's real question is, "When do I use a class for a supertype vs. using an interface for a supertype?" The answer to that, of course, is:
    Use a class when at least some of the methods have valid default implementations. Use an interface when that is not the case. And of course the two are not mutually exclusive. It's quite common to do both.
    At the end of the day, an interface is really nothing more than a class that has no non-final or non-static member variables and whose instance methods are all abstract, and from which you can multiply inherit.
    Edited by: jverd on Feb 4, 2010 1:56 PM

  • Use extends and implements or not?

    What is considered a better way of implementing classes? with the use of extends and/or implements or not?
    ex:
    public class TabPanel extends JPanel implements ActionListeneror have it return the needed Type
    ex:
    public class TabPanel implements ActionListener
    public JPanel TabPanel()
    JPanel jp = new JPanel();
    jp.add(new JLabel("Test"));
    return jp;
    }

    To extend or not to extend, that is a question. Defenitely, you must subclass when you need to override some method. You want to subclass to reuse the customized class. You want to implement an interface when you need a class implementing it.
    Regarding your example:
    public class TabPanel implements ActionListener {
         public JPanel TabPanel() {
              JPanel jp = new JPanel();
              jp.add(new JLabel("Test"));
              return jp;
    }Are you sure it will work? IMO, you do not have to specify result type and must not return anything in the constructors. Why to bother with TabPanel class? If you like to hide the scope, use {} braces in the code.
    JPanel panel = new JPanel();
    jp.add(new JLabel("Test"));
    public class NonAnanymousListener implements ActionListener {

  • Difference between Extend and Implement

    Hello guys, I still dont get it, i'm confuse, when to use Extend and when to use Implement . What's the big diference? Can anyone give me an idea?

    I keep getting an error with this class which states: "Type parameter RectangleOperand is not within it's bounds"
    import java.util.*;
    public class RectangleOperand extends Rectangle2D.Double implements Addable<RectangleOperand> 
        public RectangleOperand (double w, double h)
           super(0.0,0.0,w,h);
    public static RectangleOperand readRectangle(Scanner scan)
        double doubleValue;
        doubleValue = scan.nextDouble();
        RectangleOperand rectangle;
        return rectangle = new RectangleOperand(w,h);
    public boolean equalTo(RectangleOperand opnd2)
         boolean equal = true;
         if(this.width == opnd2.width && this.height == opnd2.height)
             equal = true;  
         else
             equal = false;
         return equal;
    public RectangleOperand plus(RectangleOperand opnd2)
         double newWidth, newHeight, width, height;
         newWidth =  (this.width)  + (opnd2.width);
         newHeight = (this.height) + (opnd2.height);
         RectangleOperand rectanglePlus = new RectangleOperand(newWidth,newHeight);
         return rectanglePlus;
    }

  • Extends and implements

    "extends" => inheritance?
    and "implements" => interface?
    or the opposite?
    and what is the difference between an
    abstract class and interface?
    Thanks in advance
    Jack

    EXTENDS
    Yes, "extends" means inheritance.
    E.g.:
    public class Chihuahua extends Dog {
    }So, from the moment you use "extends" we can say that Chihuahua IS-A Dog.
    IMPLEMENTS
    We use "implements" keyword when a class must implement one or more interfaces.
    E.g.:
    public class Chihuahua extends Dog implements SmallDog, NiceDog{
    }Interfaces are a way to simulate multiple inheritance in Java language.
    Now we also can say that a Chihuahua IS-A Dog, IS-A SmallDog and IS-A NiceDog. Yes, interfaces also causes IS-A relationships.
    ABSTRACT CLASSES x INTERFACES
    Well, some book authors says that interfaces are a more "pure version" of a abstract class. If you don't know yet, all methods of a interface are abstract, that is: the class that implements an interface MUST (with no exceptions) implements (override) all his methods. Is also important to know that all methods in a interface has a header only (no implementation), for instance:
    public interface SmallDog {
    public abstract void walkFast( );
    public abstract void hiddenBelowTheDesk( );
    }But why all methods of an interface must not be implemented? Simply because they are abstract.
    An abstract class can contain OR NOT abstract methods. In mention of the abstract methods the behavior of a class that inherits from a abstract class is the same. Look this example:
    Dog.java
    public abstract class Dog{
       private String raceName;
       public abstract void bark();
       public abstract void run();
       public String getRaceName(){
          return this.raceName;
    }You can see that we have two abstract methods: bark and run. It means that if a class extends from Dog it MUST override the methods bark and run methods. getRaceName is a method, but it isn't an abstract abstract method.
    Now let's see the Chihuahua class again:
    public class Chihuahua extends Dog{
    private BigEye leftEye;
    private BigEye rightEye;
    private BigEar leftEar;
    private BigEar rightEar;
    public void bark(){
    public void run(){
    INTERFACES INHERITS FROM OTHER INTERFACES
    Yes, it can sound crazy, but it is possible in Java. An interface can inherits from other interfaces. It ins't hard to understand. Based on the two interfaces SmallDog and NiceDog we will see how an interface can inherits from another one:
    public interface CompleteCoolDog extends SmallDog, Nicedog{
    }The interface CompleteCoolDog contains all methods from SmallDog and Nicedog, but is not obbligatory to implement them because an interface can not implement methods, only declare them. And who must implement them? The first concrete class that implements CompleteCoolDog interface.
    You can see very nice informations about interfaces and abstract classes in the books of Kathy Sierra and Bert Bates (Study guides for SCJP).
    I hope I helped you a little. Some doubt please, mail me.
    See you =)

  • Class parametrized type extends and implements, possible?

    Hi all,
    Maybe I'm not understanding it well, but every time I try to use generics for something useful I get to a point in which I need to define something like this:
    public interface MyInterface<T> {
    public T get();
    public void set(T var);
    public class MyClass<T extends Component & MyInterface<T2> > {
    T myObject;
    .... somewhere in the code:
    T2 value;
    value = myObject.get();
    To me, this would be very useful, but MyClass does not compile. I hope what I try to do is clear (I want T to be a sub class of Component that also implements a parametrized interface). I don't know what I'm doing wrong nor if this is even possible. Believe me when I say I have done a lot of research (and people thought C++ templates where complicated...).
    My main problem is having a parametrized type that contains a parametrized type and trying to have both types' parameters available for use in the class.
    Any ideas?

    This compiles in beta2:
    public class MyClass<T2, T extends Component & MyInterface<T2> > {
       T myObject = null;
      void x() {
          myObject.bar();
          T2 a = myObject.get();
    interface MyInterface<T> {
          T get();
          void set(T var);
    class Component {
        public void bar() {}
    }but removing the public modifier from Component.bar() will give the error: cannot find symbol.

  • Concrete classes implement abstract class and implements the interface

    I have one query..
    In java collection framework, concrete classes extend the abstract classes and implement the interface. What is the reason behind extending the class and implementing the interface when the abstract class actually claims to implement that interface?
    For example :
    Class Vector extends AbstractList and implements List ,....
    But the abstract class AbstractList implements List.. So the class Vector need not explicitly implement interface List.
    So, what is the reason behind this explicit definition...?
    If anybody knows please let me know..
    Thanx
    Rajendra.

    Why do you post this question again? You already asked this once in another thread and it has been extensively debated in that thread: http://forum.java.sun.com/thread.jsp?forum=31&thread=347682

  • Rollout and implementation

    Hi,
    In general or XI perspective, can you explain the difference between rollout and implementation projects.
    Some say that implementation is something where you get involve in all phases of SDLC.
    Some say it as End to End starting from requirement gathering, In XI perspective i believe there would be only implementation projects when compared to general R/3.
    Do Comment on this.

    In my view...
    An implementation would be end-to-end, from requirement gathering to post go-live for a fresh implementation of functionality and applications. In XI terms that would involve creating new interfaces to support the new scenarios.
    A roll-out would be where you are extending existing functionality and scenarios to support more geographic locations, or more business units within the organisation. E.g. you implement SAP HR for the UK based business, then after you have gone live and stabilised the environement you get France-based business to start using it. This may involve extra config and minor developments. Similarly, in XI you will probably have very little to do, unless you need to connect to loacl systems, or develop extra interfaces, or load proper codepages etc.
    Hope this helps?
    Cheers
    Manish

  • TextLayout not Serializable AND final class - can't extend and save objects

    As the title reads, I am using a TextLayout object in a class called Foo.
    I want to be able to serialize Foo and save it to the HD. This can't be done because TextLayout does not implement Serializable.
    So I tried to create a new class that extended the TextLayout class. This wasn't possible because TextLayout is defined as:
    public final class TextLayout
    extends Object
    implements Cloneable
    Basically, I have no clue how to be able to save my Foo class to the HD since I can't serialize the TextLayout object inside the Foo class. I would really appreciate help, because it is quite important that this works.
    Thanks.

    Siniz wrote:
    I have never dabbled with with transient variables, but I just read up on it and understand what you are getting at. Is this really the only way?
    The reason why I need to use TextLayout is because I need the bounding box of the text. I see no other way to get a bounding box around text than using TextLayout.That's a question for the swing/awt forums.
    I am also not entirely sure what you mean when you say I should write my own writeObject and readObject methods? You are saying I should entirely ditch the ObjectOutputStream methods?No, you implement those methods on your class in order to customize serialization. Please see the javadocs on the Serializable interface.

  • Parameterized inheritance and implementation

    I'm learning generics, and I'm having a problem getting the following to work
    I have a base class with some data/behavior
    public abstract Base<E> {
    //...Then there is a concrete class that extends Base and implements Map
    public Concrete<E extends Object & Map<K,V>> extends Base<E extends Object & Map<K,V>> implements Map<K, V>{
    //...I cannot seem to specify that the type for Base must be a Map<K, V>.
    I've thought about containing and delegating, but really Concrete IS-A Base and Concrete IS-A Map.
    Am I missing something about inheritance and generics?
    Any suggestions?

    James,
    Based on your previous posts I think you understand generics as well as I do, and in some aspects, probably better.
    I was trying to capture my thought processes (and that is quite hard since mostly this happens sub-consciously - its quite hard to drag it up into consciousness then document it, but the effort was worthwhile for me and hopefully for others as well).
    In this particular case, E is Map<K,V>, but there could be all sorts of relationships between the type variables, the idea is to identify these and back substitute them, slowly getting rid of type variables until you can't get rid of any more. The ones you are left with are the ones that need to be type parameters.
    take the other post from yesterday
    http://forum.java.sun.com/thread.jsp?thread=554360&forum=316&message=2719355
    as another worked example...
    from
    "And I'm trying to create a special generic container (List) which would only take elements that
    implement the Keyable interface above. For example:
    public class ListOfKeyables <E extends Keyable> extends AbstractList<E>{..."
    and
    "Now, besides standard List methods that use type varable 'E' in their definitions, I would also
    like to have a special method like this:
       public E getByKey(Object key)   {   ... "
    I would start with (ignoring their "E extends Keyable" suggestion, its too premature for that).
    public class ListOfKeyables < ???? > extends AbstractList<E> {
        public E getByKey(Object key) { ... }
    } but "only take elements that
    implement the Keyable interface" suggests replacing E with Keyable<K> thus
    public class ListOfKeyables < ???? > extends AbstractList<Keyable<K>> {
        public Keyable<K> getByKey(Object key) { ... }
    Note In this case the substitution getting rid of E introduced another type variable (K), thats OK, its still a step toward a solution.
    Then the original poster said "But I would like to constrain the 'key' argument in this method to be of type that is specified as a type parameter to the Keyable interface"
    So after implementing this requirement we have
    public class ListOfKeyables < ???? > extends AbstractList<Keyable<K>> {
        public Keyable<K> getByKey(K key) { ... }
    }At this point there is no more substitutions or requirements to fulfill.
    So we look through and see what type variables are still unresolved. These (in this case there is only one K), are then the type parameters of the class, and thus we have what I suggested in that post
    public class ListOfKeyables <K> extends AbstractList<Keyable<K>> {
        public Keyable<K> getByKey(K key) { ... }
    }As a final step, we need to look at the type parameters and decide if they need any constraints (K extends something), These might come from some use of the type parameter ( such as if Keyable constrained its K parameter, we would need to do the same), or from the application requirements. But in this case, there are not any.
    At a certain level of abstraction, this process is not a whole lot different to the process you use when working out what parameters a method or constructor needs (and that process also tends to happen below the consciusness threshold).
    In really simplistic terms, the answer to both "what parameters do I need" questions is "all the ones you can't get from somewhere else or derive from the ones you already have".
    Bruce

  • Extending Applet implements Runnable    --explain

    kindly give an explanation of the need to use the
    <extends Applet implements Runnable > code
    while creating an applet program is there a need to use both Applets and Runnable
    wht are the methods available in Applet class
    and Runnable interface

    The most common use of the Runnable interface is for threading.
    An applet doesn't need to implement Runnable to be run as an Applet, but an applet often needs to be doing things in the background, not just when specific user events like init, start, mouse events etc. come in. For example the applet might run some kind of animation.
    An applet should return promptly from events of the above sort, allowing the browser to get on with it's own business. If it is to do something itself one of these events needs to start a thread.
    Declaring the Applet runnable allows you to do something like:
    new Thread(this).start();for example in the init method. This starts a new thread of execution which runs the run method of the applet, which will do the background activity.
    You don't have to do it this way, you can create another Runnable object whose run method will be executed by the thread. Often you use anonymous classes for this e.g.
    new Thread(new Runnable() {
       public void run() {
              doBackgroudStuff();
        }).start();

  • What is the diffrence between extends and creating new object?

    HI ALL,
    what is the diffrence between extends and creating new object?
    meaning
    class base{
    class derived extends base{
    class base{
    class derived {
    derived(){
    base var = new base();
    can u people tell me diffence from the above examples.
    THANKS.
    ANANDA

    When you create a new object you have to supply the class to which that
    object belongs. A class can extend from another class. If it does so
    explicitly you can define the 'parent' class from which the class extends.
    If you don't explicitly mention anything, the class will implicitly extend
    from the absolute base class named 'Object'.
    Your example is a bit convoluted: when you create a Derived object,
    its constructor creates another object, i.e. an object from the class from
    which the Derived class extends.
    Extending from a class and creating an object don't have much in common.
    kind regards,
    Jos

  • Cisco Jabber for Windows in Extend and Connect mode and making outbound calls

    Hi guys,
    I've set up Cisco Jabber for Windows to use Extend and Connect to control a remote PBX endpoint. I've configured the required CTI-RD device, remote destinations, associated the users to the line and added the devices to end-user controlled device. The extend and connect part is working flawlessly without any issues. I'm able to receive inbound calls on the remote PBX endpoint and control the call (hold, resume, transfer etc.) using the Jabber call window that pops up.
    However, I'm unable to make any outbound calls via the Jabber client when in extend and Connect mode. Reading the Extend and Connect guide, I need to configure Dial Via Office (DVO) Reverse. So when the user initiates a Dial-Via-Office reverse call, CUCM calls and connect to the Extend and Connect device (CTI-RD). CUCM then calls and connects to the number the user dialled and finally connects the two call legs.
    After attempting to configure DVO-R for Jabber for Windows in Extend and Connect mode following the CUCM feature services guide, i'm unable to get any outbound calls working. From RTMT, i am receiving the following Termination Cause Code: (27) Destination out of order. What i also notice is that there is no calling number for that trace either. I would've thought that the calling party would've been the Enterprise Feature Access (EFA) number.
    Has anyone got this working or can provide some guidance?
    Thanks.

    Hi guys,
    I've set up Cisco Jabber for Windows to use Extend and Connect to control a remote PBX endpoint. I've configured the required CTI-RD device, remote destinations, associated the users to the line and added the devices to end-user controlled device. The extend and connect part is working flawlessly without any issues. I'm able to receive inbound calls on the remote PBX endpoint and control the call (hold, resume, transfer etc.) using the Jabber call window that pops up.
    However, I'm unable to make any outbound calls via the Jabber client when in extend and Connect mode. Reading the Extend and Connect guide, I need to configure Dial Via Office (DVO) Reverse. So when the user initiates a Dial-Via-Office reverse call, CUCM calls and connect to the Extend and Connect device (CTI-RD). CUCM then calls and connects to the number the user dialled and finally connects the two call legs.
    After attempting to configure DVO-R for Jabber for Windows in Extend and Connect mode following the CUCM feature services guide, i'm unable to get any outbound calls working. From RTMT, i am receiving the following Termination Cause Code: (27) Destination out of order. What i also notice is that there is no calling number for that trace either. I would've thought that the calling party would've been the Enterprise Feature Access (EFA) number.
    Has anyone got this working or can provide some guidance?
    Thanks.

  • Production and Implementation

    Hello Gurus, 
                          I want the details like....In production support what are the our usual works(roles), and what we have to do. 
                          If we are getting tickets, in which manner we have to respond for those tickets.
                          What are the exact daily works in a production support  project. And what are the exact daily works in a implementation  project.
                          What are the t-codes we have to be perfect in support and implementation.
    Please help me
    Thanks and Regards
    Kumar.

    Hi,
    It may vary in different projects.
    I can just give you a couple of general roles.
    Migration project
    • Designing mapping documents in order to check the need of creation in BW.
    • Developing various objects like Cubes, ODS, Info Sources, InfoObjects etc.
    • Designing Transfer Rules and update rules including start routines, update routines and Transfer routines as per the requirement.
    • Scheduling Info Packages to carry out the data loading process. Involved in data loading from SAP R/3 to Source layer ODSs into BW. Loaded data using Data mart, as the Business layer and Report layer ODSs get loaded from source layer ODSs using data mart functionality of BW.
    • Involve in the backfilling of historical data from present sys to SAP BW .
    • Developing the Master/Transactional data process chains considering the dependency among the BW objects and automated the triggering and monitoring of the same on daily, weekly and monthly basis.
    • Transportation of various BW components.
    • Performing unit testing and data validation of newly developed and enhanced objects in Quality BW system in terms of providing an efficient solution.
    • Responsible for overseeing the Quality procedures related to the project.
    • Responsible to deliver (Transport into Prod) the object as per the scheduled deadlines; with accuracy of deliverables by considering the quality norms.
    • Involving in the Client/Onsite communication for any client side clarifications, for assignment of work, for discussing on project status related issues, etc.
    Support project
    Data Load Monitoring:
    1.Carried out data load on a daily, weekly and monthly basis using Process chains from both SAP Source systems as well as Non-SAP Source systems such as Informatica.
    2.Resolving Data load error such as Invalid characters, Time period conversion, Currency conversion, Duplicate records, etc
    3.Ensuring the availability of the updated data in the datatarget on time.
    4.Spooling out data through Infospoke from SAP BW to systems like Trillium, Ariba (Reporting Tool)
    Ticket Resolution:
    1.Process chain modification: Working on “Optimizing Process chain” by creating new process chain considering the load dependencies.
    2.Reloading of R/3 data from different clusters – Reconciliation issues
    3.Enhancements as per Business requirement.
    Additional responsibilities:
    •Preparing design documents from the Business Requirement docs and identified the relevant data targets for satisfying the customer requirements.
    •Creation of Operational manual: BW Run & Maintain Support.
    •Process Chain Detail Documentation (Sequencing & Dependency within Local Chains).
    •Monitoring checklist Document (From Process Chain Perspective)
    •BW Doc checklist preparation
    •Table space activity with basis team.
    •Data load analysis taking into account the CPU utilization.
    •Applying Support packs and performing ORT.
    Most projects have different number of cubes with varying volume of data. You cant generalize this.
    hope this helps,
    Refer
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/08f1b622-0c01-0010-618c-cb41e12c72be
    Roles & Responsibilities for Junior & Senior consultants(Technical)
    Thanks,
    JituK

  • Printing Problem with CS 6 extended and Canon Pro 9500

    My prints are no longer coming out centered. I have the "center" box checked in the CS6 print dialogue box. The prints are not centered left to right or top to bottom.
    This seems to be a problem since I upgraded to CS 6 extended and or newest print driver for my Canon Pro 9500.
    I believe that since I did one or both of these changes there is a border (consitst of slanted hash marks around the perimiter of the print dialogue picture) in the preview of the print.
    The border segments left and right are not equal and are very uneven in width. The top and bottom borders are closer but still not even in width.
    Can anyone help me with this issue?
    Thanks,
    Dennis

    Hi there! Because the forum you originally posted in is for beginners trying to learn the basics of Photoshop, I moved your question to the Photoshop General Discussion forum, where you'll get more specialized help.
    You will be able to continue your current conversation with PECourtejoie without inturruption.

Maybe you are looking for