About Inheritance and interface!

I have to write a PQueue2 class which implements PriorityQueue interface, also PQueue2 has to extend BinaryHeap,
so at the top of the PQueue2 I should have this right?
public class PQueue2 extend BinaryHeap implements PriorityQueue {

I meant that if PQueue2 extends BinaryHeap
then it can call directly all the functions in the
e BinaryHeap right? but it can also add new methods?It's more like the public and protected methods in BinaryHeap are also the methods of PQueue2. If I create a PQueue2 outside of either class, I can call any public method defined in BinaryHeap on PQueue2.
the extends keyword creates an "is a" relationship between a class and the class it extends. Every PQueue2 instance is an instance of BinaryHeap (but not the other way around.)

Similar Messages

  • A question about inheritance and overwriting

    Hello,
    My question is a bit complicated, so let's first explain the situation with a little pseudo code:
    class A {...}
    class B extends A{...}
    class C extends B {...}
    class D extends C {...}
    class E extends B {...}
    class F {
      ArrayList objects; // contains only objects of classes A to E
      void updateObjects() {
        for(int i = 0; i < objects.size(); i++)
          A object = (A) objects.get(i); // A as superclass
         update(A);
      void update(A object) { ... }
      void update(B object) { ... }
      void update(D object) { ... }
    }My question now:
    For all objects in the objects list the update(? object) method is called. Is it now called with parameter class A each time because the object was casted to A before, or is Java looking for the best fitting routine depending on the objects real class?
    Regards,
    Kai

    Why extends is evil
    Improve your code by replacing concrete base classes with interfaces
    Summary
    Most good designers avoid implementation inheritance (the extends relationship) like the plague. As much as 80 percent of your code should be written entirely in terms of interfaces, not concrete base classes. The Gang of Four Design Patterns book, in fact, is largely about how to replace implementation inheritance with interface inheritance. This article describes why designers have such odd beliefs. (2,300 words; August 1, 2003)
    By Allen Holub
    http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html
    Reveal the magic behind subtype polymorphism
    Behold polymorphism from a type-oriented point of view
    http://www.javaworld.com/javaworld/jw-04-2001/jw-0413-polymorph_p.html
    Summary
    Java developers all too often associate the term polymorphism with an object's ability to magically execute correct method behavior at appropriate points in a program. That behavior is usually associated with overriding inherited class method implementations. However, a careful examination of polymorphism demystifies the magic and reveals that polymorphic behavior is best understood in terms of type, rather than as dependent on overriding implementation inheritance. That understanding allows developers to fully take advantage of polymorphism. (3,600 words) By Wm. Paul Rogers
    multiple inheritance and interfaces
    http://www.javaworld.com/javaqa/2002-07/02-qa-0719-multinheritance.html
    http://java.sun.com/docs/books/tutorial/java/interpack/interfaceDef.html
    http://www.artima.com/intv/abcs.html
    http://www.artima.com/designtechniques/interfaces.html
    http://www.javaworld.com/javaqa/2001-03/02-qa-0323-diamond_p.html
    http://csis.pace.edu/~bergin/patterns/multipleinheritance.html
    http://www.cs.rice.edu/~cork/teachjava/2002/notes/current/node48.html
    http://www.cyberdyne-object-sys.com/oofaq2/DynInh.htm
    http://www.gotw.ca/gotw/037.htm
    http://www.javajunkies.org/index.pl?lastnode_id=2826&node_id=2842
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=1&t=001588
    http://pbl.cc.gatech.edu/cs170/75
    Downcasting and run-time
    http://www.codeguru.com/java/tij/tij0083.shtml
    type identification
    Since you lose the specific type information via an upcast (moving up the inheritance hierarchy), it makes sense that to retrieve the type information ? that is, to move back down the inheritance hierarchy ? you use a downcast. However, you know an upcast is always safe; the base class cannot have a bigger interface than the derived class, therefore every message you send through the base class interface is guaranteed to be accepted. But with a downcast, you don?t really know that a shape (for example) is actually a circle. It could instead be a triangle or square or some other type.
    To solve this problem there must be some way to guarantee that a downcast is correct, so you won?t accidentally cast to the wrong type and then send a message that the object can?t accept. This would be quite unsafe.
    In some languages (like C++) you must perform a special operation in order to get a type-safe downcast, but in Java every cast is checked! So even though it looks like you?re just performing an ordinary parenthesized cast, at run time this cast is checked to ensure that it is in fact the type you think it is. If it isn?t, you get a ClassCastException. This act of checking types at run time is called run-time type identification (RTTI). The following example demonstrates the behavior of RTTI:
    //: RTTI.java
    // Downcasting & Run-Time Type
    // Identification (RTTI)
    import java.util.*;
    class Useful {
    public void f() {}
    public void g() {}
    class MoreUseful extends Useful {
    public void f() {}
    public void g() {}
    public void u() {}
    public void v() {}
    public void w() {}
    public class RTTI {
    public static void main(String[] args) {
    Useful[] x = {
    new Useful(),
    new MoreUseful()
    x[0].f();
    x[1].g();
    // Compile-time: method not found in Useful:
    //! x[1].u();
    ((MoreUseful)x[1]).u(); // Downcast/RTTI
    ((MoreUseful)x[0]).u(); // Exception thrown
    } ///:~
    As in the diagram, MoreUseful extends the interface of Useful. But since it?s inherited, it can also be upcast to a Useful. You can see this happening in the initialization of the array x in main( ). Since both objects in the array are of class Useful, you can send the f( ) and g( ) methods to both, and if you try to call u( ) (which exists only in MoreUseful) you?ll get a compile-time error message.
    If you want to access the extended interface of a MoreUseful object, you can try to downcast. If it?s the correct type, it will be successful. Otherwise, you?ll get a ClassCastException. You don?t need to write any special code for this exception, since it indicates a programmer error that could happen anywhere in a program.
    There?s more to RTTI than a simple cast. For example, there?s a way to see what type you?re dealing with before you try to downcast it. All of Chapter 11 is devoted to the study of different aspects of Java run-time type identification.
    One common principle used to determine when inheritence is being applied correctly is the Liskov Substitution Principle (LSP). This states that an instance of a subclass should be substitutible for an instance of the base class in all circumstances. If not, then it is generally inappropriate to use inheritence - or at least not without properly re-distributing responsibilities across your classes.
    Another common mistake with inheritence are definitions like Employee and Customer as subclasses of People (or whatever). In these cases, it is generally better to employ the Party-Roll pattern where a Person and an Organization or types of Party and a party can be associated with other entities via separate Role classes of which Employee and Customer are two examples.

  • About Classes and Interfaces

    How can we define the classes and interfaces in an interview can u give me any realtime example for this

    How can we define the classes and interfaces in an
    interviewThe easiest explanation probably is to say that an interface in Java is a special class, namely a totally abstract one, that has been given a separate name.
    Classes and interfaces (because they're classes in disguise) both constitute types, meaning that variables can be declared of them. The difference is that a class can carry implementation whereas an interface cannot (because it's totally abstract).
    Java has single inheritance of implementation which means the the inheritance of classes is restricted to exactly one while you can inherit as many interfaces you like.

  • About Messaging and Interfacing in SAP banking....

    HI all
    Just want to know the messaging formats used in the SAP banking product.
    I have no clue how the messaging and interfacing with other applications is done in SAP.
    ALso needs to know the interfacing mechanism with other applications supported by SAP.
    Plz guide and share the link....... for any info......
    If this is not the correct forum and then me know the correct one.
    Thanx in advance guys....

    Hi Rajesh,
    here you can find the interfaces used in SAP Bank Customer Accounts (BCA).
    http://help.sap.com/saphelp_erp2005vp/helpdata/en/3b/a6b9361775e748e10000009b38f839/frameset.htm
    To display interface for drilldown reporting, in the SAP Easy Access screen, choose Accounting -> Bank Applications ->SEM Banking ->Market Risk Analysis or ALM -> Tools -> Drilldown Reporting -> Display Interface Programs..
    if it helful reward points are appreciated

  • Java inheritance and interface code help required

    please help me I need your 30 mins only,,, working on assignment and I am trying to understand interface and inheritance might not need even 30 mins, please add me on skype *[deleted by moderator]*
    Or add me on
    yahoo msgr *[deleted by moderator]*
    waiting for your help.
    I have no single person friend or I can ask help from who knows java or programming. pretty much want to learn need a friend who can guide me in java.
    unfortunately have to submit assignment tomorrow.
    Thank you in advance for your time and consideration.
    Akee
    *Edited by moderator: EJP on 10/11/2012 10:38: removed your private contact details. This is a public forum, not a personal help desk. Ask your questions here or not at all.*

    Hi,
    there are lot of thread alredy posted please serach
    check following link
    http://help.sap.com/saphelp_nw04/helpdata/en/ce/1d753cab14a909e10000000a11405a/frameset.htm
    XSLT Mapping:
    http://help.sap.com/saphelp_nw04/helpdata/en/73/f61eea1741453eb8f794e150067930/content.htm
    Java Mapping:
    http://help.sap.com/saphelp_nw04/helpdata/en/e2/e13fcd80fe47768df001a558ed10b6/content.htm
    Links of blogs on java mapping...
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii
    blog
    /people/sap.user72/blog/2005/03/15/using-xslt-mapping-in-a-ccbpm-scenario
    /people/anish.abraham2/blog/2005/12/22/file-to-multiple-idocs-xslt-mapping(file to xslt mapping)
    /people/pooja.pandey/blog/2005/06/27/xslt-mapping-with-java-enhancement-for-beginners(xslt with java enhancement function)
    Regards,
    Amit

  • Inheritance and Interface invocation Query

    interface IProduct{
         void getProductName();            
    abstract class Option implements Product{
                 void exercisePrice();
                 void premiumPaid();
    class Option1 extends Option{
               // Implement all abstract methods defined in Option and IProduct.
    class Option2 extends Option{
         // Implement all abstract methods defined in Option and IProduct.
    class Trade{
               public Trade(IProduct p){
         p.getProductName()   // I can only get this method behaviour.
                    // My Query
                    // I also need to invoke the methods exercisePrice() and premiumPaid() defined in Option1 and Option2
                    // If I use instanceof,the code will get cluttered and ugly.
                                     if p instanceof Option1
                                     Option1 op1 = ((Option1) p);
                                     op1.exercisePrice();
                                      if p instanceof Option2
                                      if p instanceof OptionN
    class TestHarness{
             public static void main(String args[]){
             // Create an option
             Option1 option1 = new Option1();
             // Trade in the product
             Trade trade = new Trade(option1);
             Query:
             The Trade constructor defines IProduct.
             IProduct can be a concrete Bond,Option,CDS,IRS etc.
             How do I get the methods defined in subclasses Option1 and Option2 or for any concrete subclass of IProduct?
             Is there a way of dynamically invoking the methods of the object created?
            Or do I need to change the design.
    }

    It looks to me like you're violating the Liskov Substitution Principle.
    "The LSP says that the users of base classes should not have to do anything special in order to use derivatives."
    - R. MartinThis also violates the Open/Closed principle, because whenever you add a new Option concrete class, you're going to have to update your Trade class (it's not "closed to modification" when the environment around it changes).
    The "fix" is just that its not a good idea to force the polymorphism by using instanceof. You should either:
    1. Get rid of the IProduct interface completely and treat each product type separately.
    2. Reconsider your base class (in this case, IProduct) to see if it really can contain additional behavior applicable to all products.
    The previous post about the visitor pattern is interesting, but I don't see how it applies to this example (perhaps some more light could be shed there by the poster).

  • A question about class and interface? please help me!

    the following is program:
    interface A{
    public class B implements A{
    public static void main(String [] args){
    A a = new B();
    System.out.println(a.toString());
    }i want to ask a question, the method toString() is not belong to interface A, why a can call method toString()? the interface call the method that isn't belong to, why? please help me...

    because a.toString() call the method toString() of class Object because B implements A, but extends Object and in the class Object there is a method toString(). infact if you override the method toString() in class B, a.toString() call toString() in class B.
    try this:
    interface A {}
    public class B implements A
      public String toString()
        return "B";
      public static void main(String [] args)
        A a = new B();
        System.out.println(a.toString());
      }by gino

  • Question about inheritance and  casting

    according to the java api it said Calendar() is a super-class of GregorianCalendar(). with that said it means GC inherits all members of C(). i hope everyone agrees with me here.
    why is it necessary to do this:
    Calendar c = new GregorianCalendar();//by the way this is called implicit casting per the java tutorial.if GC inherits everything from C, and if you need members from both classes, then wouldn't it be enough to just do
    GregorianCalendar gc = new GregorianCalendar();why is it necessary to declare a variable of the parent class and assign a subclass reference to that variable?

    then why does the tutorial show this?Why not? It's legal Java. It's what I would probably write, unless I knew I was going to use some methods that were in GregorianCalendar and not in Calendar.

  • Quick question about inheritance and exceptions

    If I have two classes like this:
    public class ClassA {
        public void myMethod() throws NumberFormatException {
          throw new NumberFormatException();
    public class ClassB extends ClassA {
        public void myMethod() {
    }Does myMethod() in classA override myMethod in classB?
    And why?
    Thank you,
    V

    I just want to add that since NumberFormatException is
    a descendant of RuntimeException, you are not required
    to declare that the method throws this exception. Some
    people think it is a good idea to declare it anyway
    for clarity. Personally, I don't think so.I agree.
    I think Sun recommends that you don't declare unchecked exceptions in the method declaration, but do document them in the javadoc comments.

  • Promblem about inheritance and saving data

    I have Product class (super class) and Kitchen class (sub class). When I want to create a Kitchen object and write it to a *.txt file. However the error occurs: "java.lang.NullPointerException". What is going wrong? Please help. Thanks
    Product class
    public Product(int aProductID, String aProductName, String aOriginalCountry,
                        double aWeight, double aPrice, String aProductCategory,
                        String aInputDate, String aExpiryDate, double aVatPrice,
                        String aManufacturerName, String aManufacturerAddress,
                        String aWarranty)
        productID = aProductID;
        productName = aProductName;
        originalCountry = aOriginalCountry;
        weight = aWeight;
        price = aPrice;
        productCategory = aProductCategory;
        inputDate = aInputDate;
        expiryDate = aExpiryDate;
        vatPrice = aVatPrice;
        manufacturerName = aManufacturerName;
        manufacturerAddress = aManufacturerAddress;
        warranty = aWarranty;
      }Kitchen class
    public Kitchen(int aProductID, String aProductName, String aOriginalCountry,
                         double aWeight,
                         double aPrice, String aProductCategory,
                         String aInputDate, String aExpiryDate, double aVatPrice,
                         String aManufacturerName, String aManufacturerAddress,
                         String aWarranty)
       super(aProductID, aProductName, aOriginalCountry, aWeight, aPrice,
               aProductCategory, aInputDate, aExpiryDate, aVatPrice,
             aManufacturerName, aManufacturerAddress, aWarranty);
    }The method that write the method to text file
    public void writeInfo()
        try{
          PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter
          ("C:\\Documents and Settings\\Charles\\My Documents\\Kitchen.txt", true)));
          out.println();
          out.write(Integer.toString(productID));
          out.write("  ");
          out.write(productName);
          // More data to write...
          out.flush();
          out.close();
         catch(IOException ex)
            ex.printStackTrace();
    }

    This is the Product Class
    package supermarket;
    import java.io.*;
    import javax.swing.*;
    public class Product {
      // Declare variables
      protected int productID;
      protected String productName;
      protected String originalCountry;
      protected double weight;
      protected double price;
      protected String productCategory;
      protected String inputDate;
      protected String expiryDate;
      protected double vatPrice;
      protected String manufacturerName;
      protected String manufacturerAddress;
      protected String warranty;
      protected double originalPrice;
      protected double calculatedVATPrice;
      public Product() {
        productID = 0;
        productName = "";
        originalCountry = "";
        weight = 0.0;
        price = 0.0;
        vatPrice = 0.0;
        manufacturerName = "";
        manufacturerAddress = "";
        warranty = "YES";
      public Product(int aProductID, String aProductName, String aOriginalCountry,
                           double aWeight, double aPrice, String aProductCategory,
                           String aInputDate, String aExpiryDate, double aVatPrice,
                           String aManufacturerName, String aManufacturerAddress,
                           String aWarranty)
        productID = aProductID;
        productName = aProductName;
        originalCountry = aOriginalCountry;
        weight = aWeight;
        price = aPrice;
        productCategory = aProductCategory;
        inputDate = aInputDate;
        expiryDate = aExpiryDate;
        vatPrice = aVatPrice;
        manufacturerName = aManufacturerName;
        manufacturerAddress = aManufacturerAddress;
        warranty = aWarranty;
      public void writeInfo()
        try{
        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter
        ("C:\\Documents and Settings\\Charles\\My Documents\\testing.txt", true)));
        out.println();
        out.write(Integer.toString(productID));
        out.write("  ");
        out.write(productName);
        out.write("  ");
        out.write(originalCountry);
        out.write("  ");
       // and more data to save...
        out.flush();
        out.close();
        catch(IOException ex)
         ex.printStackTrace();
    public void displayInfo(JLabel D1)
        try
          BufferedReader in = new BufferedReader(new FileReader
          ("C:\\Documents and Settings\\Charles\\My Documents\\testing.txt"));
          String fromAll = in.readLine();
          D1.setText(fromAll);
        catch(IOException ex)
        ex.printStackTrace();
    }This is the Kitchen class
    package supermarket;
    import supermarket.Product;
    import java.io.*;
    import javax.swing.*;
    public class Kitchen extends Product{
          private int productID;
          private String productName;
          private String originalCountry;
          private double weight;
          private double price;
          private String productCategory;
          private String inputDate;
          private String expiryDate;
          private double vatPrice;
          private String manufacturerName;
          private String manufacturerAddress;
          private String warranty;
          private double originalPrice;
          private double calculatedVATPrice;
         public Kitchen() {
         super();
      // The constructor is not working......
      public Kitchen(int aProductID, String aProductName, String aOriginalCountry,
                          double aWeight, double aPrice, String aProductCategory,
                         String aInputDate, String aExpiryDate, double aVatPrice,
                         String aManufacturerName, String aManufacturerAddress, String aWarranty)
       super(aProductID, aProductName, aOriginalCountry, aWeight, aPrice,
                aProductCategory, aInputDate, aExpiryDate, aVatPrice,
                aManufacturerName, aManufacturerAddress, aWarranty);
    public void writeInfo()
        try{
          PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter
         ("C:\\Documents and Settings\\Charles\\My Documents\\Kitchen.txt", true)));
          out.println();
          out.write(Integer.toString(productID));
          out.write("  ");
          out.write(productName);
          out.write("  ");
          out.write(originalCountry);
          // and more data to save...
          out.flush();
          out.close();
    catch(IOException ex)
      ex.printStackTrace();
    public void displayInfo(JLabel E1)
       try
         BufferedReader in = new BufferedReader(new FileReader
        ("C:\\Documents and Settings\\Charles\\My Documents\\Kitchen.txt"));
         String fromAll = in.readLine();
         E1.setText(fromAll);
       catch(IOException ex)
         ex.printStackTrace();
    }Is this look better? Please help. Thanks

  • Inheritance vs Interfaces

    Hi,
    I know that interfaces are used to create an empty class which cannot be instantiated as it is not implemented. The user will have to eventually implement all or some of the methods defined. Now my problem lies here...cant' the user simply use inheritance and then override the method/s which he/she wants to behave differently from the parent class? I mean whats the reason/s for having interfaces, and what are the differences between inheritance and interfaces?
    I apologize for asking such a simple question but still cant understand the basic concept after I Googled it out.
    Thanks for your attention
    Dave
    Edited by: BeginnerDave on Aug 19, 2009 6:12 AM

    BeginnerDave wrote:
    I know that interfaces are used to create an empty class which cannot be instantiated as it is not implemented.Sort of, but I prefer to think of it as a type rather than a class. The Interface defines a type and the methods that must be implemented for it. A blueprint, if you like.
    The user will have to eventually implement all or some of the methods defined.Actually, in order for it to be instantiated, all methods will have to be implemented.
    Now my problem lies here...cant' the user simply use inheritance and then override the method/s which he/she wants to behave differently from the parent class?Yup. But not everything fits neatly into an inheritance structure.
    I mean whats the reason/s for having interfaces, and what are the differences between inheritance and interfaces?Lots; but just for starters: A class can implement many interfaces, but it can have only one superclass.
    So basically, you go for interfaces when you want to share empty classes....and inheritance when you want to modify class type ...I think you need to read a bit more about this.
    Inheritance is only applicable when one class is a specialized form of another: eg:
    Shape-->Circle
    Mammal-->Primate-->Human
    Product-->Cereal-->CornFlakes
    Interfaces can be implemented by any class in any combination, and it then takes on the type of that Interface, which is why it's perfectly legal to say:
    List myList = new ArrayList();because List is an interface, and ArrayList is a class that implements List.****
    HIH a bit.
    Winston
    ****(BTW, it's better to use generics when defining Lists, but I didn't want to clutter the example).

  • 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

  • BDC and Interface

    Hi All
    1) Please give me a clear picture about BDC and Interfaces, what are the differences between?
    2) What is the usage of Update Mode(Synchronous, Asynchronous and Local), please explain me differences between them?
    Awaiting for your response.
    Regards
    Praveen

    1)
    http://help.sap.com/saphelp_47x200/helpdata/en/fa/097140543b11d1898e0000e8322d00/frameset.htm
    2)
    You use the UPDATE parameter to specify how updates produced by a transaction should be processed. You can select between these modes:
    A Asynchronous updating. In this mode, the called transaction does not wait for any updates it produces to be completed. It simply passes the updates to the SAP update service. Asynchronous processing therefore usually results in faster execution of your data transfer program.
    Asynchronous processing is NOT recommended for processing any larger amount of data. This is because the called transaction receives no completion message from the update module in asynchronous updating. The calling data transfer program, in turn, cannot determine whether a called transaction ended with a successful update of the database or not.
    If you use asynchronous updating, then you will need to use the update management facility (Transaction SM12) to check whether updates have been terminated abnormally during session processing. Error analysis and recovery is less convenient than with synchronous updating.
    S Synchronous updating. In this mode, the called transaction waits for any updates that it produces to be completed. Execution is slower than with asynchronous updating because called transactions wait for updating to be completed. However, the called transaction is able to return any update error message that occurs to your program. It is much easier for you to analyze and recover from errors.
    L Local updating. If you update data locally, the update of the database will not be processed in a separate process, but in the process of the calling program. (See the ABAP keyword documentation on SET UPDATE TASK LOCAL for more information.)
    Regards,
    Rich Heilman

  • Question about Classes, Abstract  Classes and Interfaces.

    I have been experimenting with Classes, Abstract Classes and Interfaces and wonder if anyone can explain this to me.
    I was looking for a way to assign a value to a variable and then keep it fixed for the session and have devised this.
    First I create an abstract class like this:
    public abstract class DatabaseConnection {
    private static String ServerName = null;
    public static void setServerName(String serverName) {
              ServerName = serverName;
         public static String getServerName() {
              return ServerName;
    }and then I created an interface
    public interface DatabaseAccess {
         String servername = DatabaseConnection.getServerName();
    }And finally the class itself with some test lines in it so I could see what was going on:
    public class CreateDatabase extends DatabaseConnection implements DatabaseAccess {
         public static void main (String args[]){
              new CreateDatabase();
         public CreateDatabase(){     
              setServerName("Server Name 1");
              System.out.println ("Before update ");
              System.out.println ("ServerName from Interface           = " + servername);
              System.out.println ("ServerName from Abstract Class = " + getServerName());
              System.out.println ("After update ");
              setServerName("Server Name 2");
              System.out.println ("ServerName from Interface           = " + servername);
              System.out.println ("ServerName from Abstract Class = " + getServerName());
              System.out.println ("==========================");
    }The output I get from the above is:
    Before update
    ServerName from Interface           = Server Name 1
    ServerName from Abstract Class = Server Name 1
    After update
    ServerName from Interface           = Server Name 1
    ServerName from Abstract Class = Server Name 2
    ==========================I also tried this in another class which calls the above class to see if I get the same effect
    public class CheckDatabaseAccess {
         public static void main (String args[]){
              new CreateDatabase();
              CreateDatabase.setServerName("Server 3");
              System.out.println("CreateDatabase "+CreateDatabase.servername);
              CreateDatabase.setServerName("Server 4");
              System.out.println("CreateDatabase "+CreateDatabase.servername);
              CreateDatabase.setServerName("Server 5");
              System.out.println("CreateDatabase "+CreateDatabase.servername);
    }The output of which is this:
    Before update
    ServerName from Interface           = Server Name 1
    ServerName from Abstract Class = Server Name 1
    After update
    ServerName from Interface           = Server Name 1
    ServerName from Abstract Class = Server Name 2
    ==========================
    CreateDatabase Server Name 1
    CreateDatabase Server Name 1
    CreateDatabase Server Name 1Can anyone explain why I appear to only be able to change or set the ServerName only the once?
    Is this the correct way to do it? If it is it's exactly what I am looking for, a way to set the value of variable once in a session and then prevent it being changed.
    Or is there a better way of doing this.
    What I want to use this for is for example, storing the accesses to a database on a server. I won't know what server the database will be stored on nor what the database is called so I create an INI file which stores this information in encrypted format, which is set by the database administrator. It occurs to me I can use this method to then retrieve that data once and once only from the INI file and use that throughout the life of the session to access the database.
    Any help appreciated
    Regards
    John

    Not gonna read all of it, but this jumps out:
    public abstract class DatabaseConnection {
    private static String ServerName = null;
    public interface DatabaseAccess {
         String servername = DatabaseConnection.getServerName();
    }You have two completely separate variables (with two different names, for that matter, since you were inconsistent in your capitalization, but it wouldn't make a difference if they did have the same name with the same case). And the one in the interface is implicitly public, static, and final.
    Anytime you refer to "servername" through a reference of type DatabaseAccess, it refers to the one declared in the interface.
    Anytime you refer to "ServerName" inside the DatabaseConnection class, it refers to the one declared in that class.

  • A little question about inheritance

    Can someone explain this to me?
    I have been reading about inheritance in Java. As I understand it when you extend a class, every method gets "copied" to the subclass. If this is so, how come this doesn't work?
    class inherit {
        int number;
        public inherit(){
            number = 0;
        public inherit(int n){
            number = n;
    class inherit2 extends inherit{
        public inherit2(int n, int p){
            number = n*p;
    class example{
        public static void main(String args[]){
            inherit2 obj = new inherit2();
    }What I try to do here is to extend the class inherit with inherit2. Now the obj Object is of inherit2 class and as such, it should inherit the constructor without parameters in the inherit class or shouldn't it ??? If not, then should I rewrite all the constructors which are the same and then add the new ones??

    I believe you were asking why SubClass doesn't have the "default" constructor... after all, shouldn't SubClass just have all the contents of SuperClass copy-pasted into it? Not exacly. ;)
    (code below... if you'd like, you can skip the first bit, start at the code, and work your way down... depending on if you just started, the next bit may confuse rather than help)
    Constructors are special... interfaces don't specify them, and subclasses don't inherit them. There are many cases where you may not want your subclass to display a constructor from it's superclass. I know this sounds like I'm saying "there are many cases where you won't want a subclass to act exactly like a superclass, and then some (extend their functionality)", but its not, because constructors aren't how an object acts, they're how an object gets created.
    As mlk said, the compiler will automatically create a default constructor, but not if there is already a constructor defined. So, unfortunatley for you, there wont be a default constructor made for SubClass that you could use to create it.
    class SuperClass { //formerly inherit
    int number;
    public SuperClass () { //default constructor
    number = 0;
    public SuperClass (int n) {
    number = n;
    class SubClass extends SuperClass { //formerly inherit2
    //DEFAULT CONSTRUCTOR, public SubClass() WILL NOT BE ADDED BY COMPILER
    public SubClass (int n, int p) {
    number = n*p;
    class Example {
    public static void main(String [] args) {
    //attempted use of default constructor
    //on a default constructorless subclass!
    SubClass testSubClass = new SubClass();
    If you're still at a loss, just remember: "Constructors aren't copy-pasted down from the superclass into the subclass!" and "Default constructors aren't added in if you add your own constructor in" :)
    To get it to work, you'd have to add the constructor you used in main to SubClass (like doopsterus did with inheritedClass), or use the constructor you defined in SubClass for when you make a new one in main:
    inherit2 obj = new inherit2(3,4);
    Hope that cleared things up further, if needed. By the way, you should consider naming your classes as a NounStartingWithACapital, and only methods as a verbStartingWithALowercase

Maybe you are looking for