In which case we need a class with all methods defined as abstract ?

In which case we need : A class with all methods defined as abstract (or should we go for Interface always in this case)

The concept of interface and abstract class overlaps sometime, but we can have the following thumb rule to use them for our specific need:
1) Interface: This should be use for code structuring. They standardize your application by providing a specific contract within and outside. If you think abstract class also provide structure, then reconsider as it limits the structure re-usability when there are many super-classes to inherit from. Java allow multiple inheritance by interface and not by Abstract class.
2) Abstract Class: This should be use for code-reusability. Interface doesn't have any code so can't be used for code-reusability.
Actually we can use both to provide the best.Taking a refernce to J2EE framework, the "Servlet" is an interface. It laids down the contract/structure for any code to be a servlet.
But the "GenericServlet" class is an abstract class which provides implementation of some of the methods defined in the "Servlet" interface and leave some method abstract.
Thus we see that the "Servlet" interface standardise the structure and the "GenericServlet" abstract class gives code re-usability.
Original Question:
In which case we need a class with all methods defined as abstract ?To this question, as all methods are abstarct we don't have option for code-reusability. so why not add standard structure concept to your application. So if there is not any restriction on making the field variable(if any) as final, we should go with the interface concept.

Similar Messages

  • Which libary I need to import for Rectangle method

    Anybody else knows which file we need to import for Rectangle method
    Example:
    mc.startDrag(false, new Rectangle(40,50,50,60));

    Hi,
           create a new ActionScript file...
         and click the left top corner + sign.That menu having a all classes.......
    regards
    Kamal

  • Aperture Vault vs Time Machine~which is best to retrive photos with all info

    Aperture Vault vs Time Machine~which is best to retrive photos with all info?

    Both will restore your Aperture library. And both will not allow to restore single images. You always have to restore the complete library.
    The difference is, that Aperture vaults are archival backups. You make a snapshot at a certain point of time. Time Machine will give  you the option to go back in time to several different moments. A vault is snapshot of only one moment and you would need to create several vault to be able to go back to earlier versions of the library.

  • Testing ActionScript classes with native methods?

    Hi,
    I have an ActionScript class that I'm writing and would like to test using FlexUnit.
    The only issue is that the ActionScript class has a member in it that is a class with native methods.
    So, I get the following error when trying to run a test of that ActionScript class:
    VerifyError: Error #1079: Native methods are not allowed in loaded code.
    Does anyone know of a way to get around this?  FlexUnit seems not to like native methods being present.
    Thanks,
    Matt

    Hi casdvm,
    by definition, you only own objects that you created using one of the alloc* methods, copy: or new:. All other objects (IIRC with a few noted exceptions) are autoreleased.
    If you create convenience methods in your own class, you should follow the same rule. For example, if you have a class Pet and want to implement the method +petWithName, your code might look something like that:
    + petWithName: (NSString *)name
    return [[[Pet alloc] initWithName: name] autorelease];
    Alex

  • Enhanced SAP class with new methods - Not showing these from standard task

    Dear Gurus,
    I have enhanced SAP standard class with new methods. After I have activated my new methods and would like to create a workflow task using these new methods. when I create a task and input object category as "ABAP Class" and object type is SAP enhanced class. When I try to drop down for methods SAP is not showing my new methods. I do not know why. Am I missing any? Any help would be appreciated.
    Note: Remember I am trying to use SAP ABAP class custom methods.
    Thanks,
    GSM

    Hi,
    Your thread has had no response since it's creation over
    2 weeks ago, therefore, I recommend that you either:
    - Rephrase the question.
    - Provide additional Information to prompt a response.
    - Close the thread if the answer is already known.
    Thank you for your compliance in this regard.
    Kind regards,
    Siobhan

  • Can u send me the link which describes me in about bdc with direct method

    Can u send me the link which describes me in about bdc with direct method with examples in detail

    Hi,
    http://help.sap.com/saphelp_nw04/helpdata/en/eb/3e7cf7940e11d295df0000e82de14a/frameset.htm
    and
    http://help.sap.com/saphelp_nw04/helpdata/en/eb/3e7cf7940e11d295df0000e82de14a/frameset.htm
    For BDC:
    http://myweb.dal.ca/hchinni/sap/bdc_home.htm
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/bdc&
    http://www.sap-img.com/abap/learning-bdc-programming.htm
    http://www.sapdevelopment.co.uk/bdc/bdchome.htm
    http://www.sap-img.com/abap/difference-between-batch-input-and-call-transaction-in-bdc.htm
    http://help.sap.com/saphelp_47x200/helpdata/en/69/c250684ba111d189750000e8322d00/frameset.htm
    http://www.sapbrain.com/TUTORIALS/TECHNICAL/BDC_tutorial.html
    Check these link:
    http://www.sap-img.com/abap/difference-between-batch-input-and-call-transaction-in-bdc.htm
    http://www.sap-img.com/abap/question-about-bdc-program.htm
    http://www.itcserver.com/blog/2006/06/30/batch-input-vs-call-transaction/
    http://www.planetsap.com/bdc_main_page.htm
    reward if useful
    regards,
    Anji

  • Which driver supports the previous, next, last, first methods defined in jd

    which driver supports the previous, next, last, first methods defined in jdbc2.0?

    erm... all JDBC2.0 drivers.
    Check out http://industry.java.sun.com/products/jdbc/drivers u can do a search for JDBC2.0 Drivers.
    Hope this helps!
    Sam

  • Which cases we need to restart the J2EE Engine

    Hi,
    In our project , we have only two servers
    One for Development & Testing
    Second for Production.
    Because of the Development and testing happening in the same mechine, we are requesting the client to get another server, Because we are getting problem to use the same server for develpment and testing .
    when ever we make any changes at the bapi side, to reflect those changes in the front end or webdynpro, we need to restart, if we make any changes in the, Config Tool or Visual Admin, we need to restart.
    At the same time couple users are working in the same server for tesing. It is troubling them when ever we make the restart.
    So we are getting lot of complaits when ever we restart the server.
    so we decided to request new server for development seperately. so , one of our administrators asking for proofs from the SAP coumentation, why do we need restart many times.
    To get the new server for development, we need to show documentation from the sap for resons of restart. i have got some documentation for restart when it requires.
    If any of you have some links related to this restart requires done on which cases?
    can u please forward it me.
    Regards
    Vijay

    Hi Vijay,
    Find the official documentation for J2EE engine in the below link
    <a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/1a/819d42449b0731e10000000a1550b0/content.htm">http://help.sap.com/saphelp_nw2004s/helpdata/en/1a/819d42449b0731e10000000a1550b0/content.htm</a>
    Regards,
    Sudeep

  • Abstract Method in a Class with implemented method

    I have a class which already has methods Implemented.I mean thse metgods are not abstract.I want only one method to be abstarct which will be overrideen by its subclass or derived Class
    I have never tried this
    Does anyone knows how to do this
    If yes could you give me syntax of the method
    Thanks in advance
    CSJakharia

    javax.swing.JComponent is an example of an abstract
    class with no abstract methods. That is why the
    following works:
    JComponent component = new JComponent(){};
    Not to forget you cannot instantiate abstarct classes
    public abstract class Test
    public String getName()
    return "Mike";
    public static void main(String[] args)
    Test tt = new Test();
    System.out.println(tt.getName());
    }and you would get the error
    The type Test cannot be instantiated.
    You remove the abstract keyword and it would compile
    good.No I am not misinterpreting I know what he is saying but I am closing the door of misinterpretation which I felt was possible. ;)
    cheers

  • Help with Declaring a Class with a Method and Instantiating an Object

    hello all i am having trouble understanding and completing a lab tutorial again!
    im supposed to compile an run this code then save work to understand how to declare aclass with a method an instantiate an object of the class with the following code
    // Program 1: GradeBook.java
    // Class declaration with one method.
    public class GradeBook
    // display a welcome message to the GradeBook user
    public void displayMessage()
    System.out.println( "Welcome to the Grade Book!" );
    } // end method displayMessage
    } // end class GradeBook
    // Program 2: GradeBookTest4.java
    // Create a GradeBook object and call its displayMessage method.
    public class GradeBookTest
    // main method begins program execution
    public static void main( String args[] )
    // create a GradeBook object and assign it to myGradeBook
    GradeBook myGradeBook = new GradeBook();
    // call myGradeBook's displayMessage method
    myGradeBook.displayMessage();
    } // end main
    } // end class GradeBookTest4
    i saved above code as shown to working directory filename GradeBookTest4.java
    C:\Program Files\Java\jdk1.6.0_11\bin but recieved error message
    C:\Program Files\Java\jdk1.6.0_11\bin>javac GradeBook4a.java GradeBookTest4.java
    GradeBookTest4.java:2: class, interface, or enum expected
    ^
    GradeBookTest4.java:27: reached end of file while parsing
    ^
    2 errors
    can someone tell me where the errors are because for class or interface expected message i found a solution which says 'class? or 'interface' expected is because there is a missing { somewhere much earlier in the code. i dont know what "java:51: reached end of file while parsing " means or what to do to fix ,any ideas a re appreciated                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Doesn't solve your problem, but this works for me...
    public class GradeBook
      public void displayMessage() {
        System.out.println( "Welcome to the Grade Book!" );
      public static void main( String args[] ) {
        try {
          GradeBook gradeBook = new GradeBook();
          gradeBook.displayMessage();
        } catch (Exception e) {
          e.printStackTrace();
    }

  • Creation of a static class with private methods

    I'm new to java programming and am working on a project where I need to have a static class that does a postage calculation that must contain 2 private methods, one for first class and one for priority mail. I can't seem to figure out how to get the weight into the class to do the calculations or how to call the two private methods so that when one of my other classes calls on this class, it retrieves the correct postage. I've got all my other classes working correct and retrieving the information required. I need to use the weight from another class and return a "double". Help!!!
    Here's my code:
    * <p>Title: Order Control </p>
    * <p>Description: Order Control Calculator using methods and classes</p>
    * <p>Copyright: Copyright (c) 2002</p>
    * <p>Company: Info 250, sec 001, T/TH 0930</p>
    * @author Peggy Blake
    * @version 1.0, 10/29/02
    import javax.swing.*;
    public class ShippingCalculator
    static double firstClass, priorityMail;
    //how do I get my weight from another class into this method to use??? not sure I understand how it works.
    public static double ShippingCalculator(double weight)
    String responseFirstClass;
    double quantity, shippingCost;
    double totalFirstClass, firstClass, priorityMail, totalShipping;
    double priorityMail1 = 3.50d;//prioritymail fee up to 1 pound
    double priorityMail2 = 3.95d;//prioritymail fee up to 2 pounds
    double priorityMail3 = 5.20d;//prioritymail fee up to 3 pounds
    double priorityMail4 = 6.45d;//prioritymail fee up to 4 pounds
    double priorityMail5 = 7.70d;//prioritymail fee up to 5 pounds
    quantity = 0d;//ititialization of quantity
    // weight = 0d;//initialization of weight
    // shippingCost = 0d;
    //calculation of the number of items ordered..each item weights .75 ounces
    quantity = (weight/.75);
    if (quantity <= 30d)
    //add 1 ounce to quantities that weigh less than 30 ounces
    weight = (weight + 1);
    else
    //add 2 ounces to quantities that weigh more than 30 ounces
    weight = (weight + 2);
    if (weight > 80d)
    //message to orderclerk ..order over 5 lbs, cannot process
    JOptionPane.showMessageDialog(null, "Order exceeded 5 lbs, cannot process");
    //exit system, do not process anything else
    System.exit (0);
    else
    if (weight < 14d)
    //send message to customer: ship firstclass or priority, y or n
    responseFirstClass = JOptionPane.showInputDialog(null, "Ship first class? y or n?");
    if (responseFirstClass.equals("y"))
    //compute FirstClass shipping cost
    totalFirstClass = ((weight - 1) * .23d) + .34d;
    firstClass = totalFirstClass;
    else
    //compute PriorityMail cost for orders less than 14 ounces
    priorityMail = (priorityMail1);
    else
    if (weight <=16d)
    //compute totalshipping for orders up to 16 ounces
    priorityMail = (priorityMail1);
    else
    if (weight <=32d)
    //compute totalshipping for orders up to 32 ounces
    priorityMail = (priorityMail2);
    else
    if (weight <=48d)
    //compute totalshipping for orders up to 48 ounces
    priorityMail = (priorityMail3);
    else
    if (weight <= 64d)
    //compute totalshipping for orders up to 64 ounces
    priorityMail = (priorityMail4);
    else
    //compute totalshipping for orders up to 80 ounces
    priorityMail = (priorityMail5);
    priorityMail = 0d;
    firstClass = 0d;
    firstClassMail ();
    priorityMailCost ();
    //I think this is where I should be pulling the two methods below into my code, but can't figure out how to do it.
    shippingCost = priorityMail + firstClass;
    return (shippingCost);
    }//end method calculate shipping
    private static double firstClassMail()//method to get first class ship cost
    return (firstClass);
    }//end method firstclass shipping
    private static double priorityMailCost()//method to get priority mail cost
    return (priorityMail);
    }//end method priorityMail
    }//end class shipping calculator

    public class A {
    public String getXXX () {
    public class B {
    A a = new A();
    public void init () {
    a.getXXX();
    }

  • Extending classes with private methods?

    my understanding of extending classes is that you gain all the functions and methods of that class thus You could over ride any one of them. How ever I am confused on weather or not you inherit and can over ride private methods of the class you are extending or if you have to have all methods public in an extended class.
    hope that makes sense, an example can bee seen bellow.
    package
         public class Class1
              public function apples():void
                   //some code
              private fnctuin bananas():void
                   //more code
    package
         public class Class2 extends Class 1
              override public function apples():void
                   //i changed code
              //can I over ride bananas?

    you can only override methods that would be inherited.  a private method won't be inherited:
    http://www.kirupa.com/forum/showthread.php?223798-ActionScript-3-Tip-of-the-Day/page5

  • For which cases we need to soap adapter ?

    Hi All,
    where we can use soap adapter?
    we can use soap adapter all cases or any specific case like web service.

    Hi Kishore,
    Go through the below links,
    When to use SOAP adapter
    Which Adapter to use - HTTP or SOAP Adapter?
    When do we use SOAP adapter or HTTP adapter?
    If you are new to SCN, its always a good practice to search before posting the questions directly because almost all the questions are already answered by the experts here.

  • Singleton class with static method

    Hi,
    I have made a fairly simple singletion class STClass. EX:
    Consider tow cases
    CASE-1:
    private static STClass singleInstance;
    private static int i;
    private STClass()
    public static STClass instance()
         if (singleInstance == null)
              singleInstance = new STClass();
              loadConfigFile("XYZ");
         return singleInstance;
    private static void loadConfigFile(String fileName)
         //SOME CODE in which use private variable "i"
    CASE-2:
    private static STClass singleInstance;
    private int i;
    private STClass()
         loadConfigFile("XYZ");
    public static STClass instance()
         if (singleInstance == null)
              singleInstance = new STClass();
         return singleInstance;
    private void loadConfigFile(String fileName)
         //SOME CODE in which use private variable "i"
    What is the differnce between two case and which one will be best and why???
    Someone told me "If u keep variables and methods as static the the whole purpose of singleton class is defeated"
    please justify this statement

    It seems to me that this way should be more "correct":
    public class STClass {
    private static STClass singleInstance;
    private int i;
    private STClass() {
    public static STClass getInstance() {
    if (singleInstance == null) {
    singleInstance = new STClass();
    singleInstance.loadConfigFile("XYZ");
    return singleInstance;
    private void loadConfigFile(String fileName) {
    //SOME CODE in which use private variable "i"
    }And it is also compatible with your CASE-2.
    Hope this helped,
    Regards.I wouldnot agree with this piece of code here because of JMM bug. check this
    http://www.javaworld.com/jw-02-2001/jw-0209-double-p2.html
    What about proposing your own version, explained ?...

  • Need some help with all of the jumper settings.

    Wow, this has been some ordeal. I inherited a G4 iMac from a friend, which has been a great deal of trouble to me, particularly with the jumper settings. Anybody like dealing with that? Come on down...
    So here's my situation. The hard drive in the iMac was dead. No big deal I'll just replace it, so I got a drive which I'm SURE is compatible. I plugged it in paying little attention to the jumper settings on it because until the beginning of this ordeal I knew nothing about jumper settings.
    Now this is where it starts making no sense... I booted the computer while holding down the mouse button to eject, then put in a 10.2 OS disc, and then restarted holding C to boot from the install disc. It loaded fine but when I got to the installation step where I pick a drive to install it to, there were NO drives in the menu.
    Maybe it needs to be formatted, right? WRONG. From the install screen I clicked open disc utility, and found the drive there in the list. It recognizes the drive, so why can't I install to it? I tried reformatting the drive as Mac os extended or whatever, and this made no difference.
    This is where the jumpers come into play. I can't find jumper settings anywhere online for the DVD-RW Pioneer DVR-104PC Superdrive, so I've left the jumper on the optical drive alone and tried toying with the jumper settings on the HD instead, but I tried every possible setting and none of them worked to allow the installer to see my hard drive.
    So what do you all think the deal is? If you know what the various jumper positions are for this particular optical drive, by all means let me know so I can toy around some more. Or if you know an alternate solution other than what I've suggested, please share. I've already invested money in a drive, some thermal paste, and Torx screwdrivers for this thing, so I really just want to get it working.... Let me know...

    Hey Michael,
    Here's the link to the WD support site:
    http://wdc.custhelp.com/cgi-bin/wdc.cfg/php/enduser/stdadp.php?pfaqid=84
    My experience with WDs is that when they need to be "Master single" I use no jumper. That's in most Mac setups including the iMac G4s. Which drove me nutz until I figured that out. All other manufactures I've run into need a jumper across the first pair on the left as you look at it from the back. WD is the odd man out.
    Also if you Google:
    "western digital jumpers" the 2nd response you get is from OWC (macsales.com) and they're telling you to use the slave setting. Don't know about that I've always used no jumpers but I see a lot of hard drives so next time..
    Richard

Maybe you are looking for