Abstract Class Problem

HI, I have 4 classes and the hierarchy of those classes is as follows:
DBCachedRecord
|
ServiceHeader
|
ServiceHeader22, ServiceHeader25
I made ServiceHeader abstract and ServiceHeader22 and ServiceHeader25 need to call constructors of DBCachedRecord. When i do super(..), I got the error Constructor cannot find in ServiceHeader.
There are few static methods as well in each of the class which I want to access those. And I have a method getService in ServiceHeader which decides which serviceHeader to use (either 22 or 25).
I found this really a hard one and I cannot find a solution yet. Would anybody help me in resolving this scenario.
Thanks

When i do super(..), I got the error
Constructor cannot find in ServiceHeader.So what is your question? You believe the compiler, right? You need to either add the constructor you want to call, or call a constructor that already exists. Keep in mind the default constructor thing - if you don't know what I'm talking about then that may be the problem.
There are few static methods as well in each of the
class which I want to access those. And I have a
method getService in ServiceHeader which decides which
serviceHeader to use (either 22 or 25).Generally having a superclass know anything about its subclasses is a bad design. Consider making these methods non-static and overriding them in the subclasses. IMO this is OK to do even if they don't use non-static data, in order to get the appropriate class-specific behavior. Others may disagree though, I don't know.

Similar Messages

  • Problem compiling Abstract class

    Hi
    I have writting an abstract class Sort.java and another class BubbleSort.java. I am having problems compiling BubbleSort.java class.
    The following is the error message
    BubbleSort.java:8: missing method body, or declare abstract
         public int doSorting(int[] array);
    ^
    BubbleSort.java:11: return outside method
              return num;
    ^
    The following is the code
    public abstract class Sort
    public abstract int doSorting(int[] array);
    }// End of class
    public class BubbleSort extends Sort
    private int num = 2;
    public int doSorting(int[] array);
    num = num + 2;
    return num;
    } // end of class

    Remove the semi-colon.
    public int doSorting(int[] array); // <------- there

  • Problems with extension of generic abstract class

    Hello,
    I'm having some problems with the extension of a generic abstract class. The compiler tells me I have not implemented an abstract method but I think I have. I have defined the following interface/class hierarchy:
    public interface Mutator<T extends Individual<S>, S> {
         public void apply( T<S> ind );
    public abstract class AbstractMutator<T extends Individual<S>, S> implements Mutator<T, S> {
         public abstract void apply( T<S> ind );
    }Now I implement AbstractMutator as such:
    public class BinaryMutator extends AbstractMutator<StringIndividual<Integer>, Integer> {
         public void apply( StringIndividual<Integer> ind ) { ... }
    }The compiler says:
    BinaryMutator.java:3: ga.BinaryMutator is not abstract and does not override abstract method apply(ga.Individual<java.lang.Integer>) in ga.AbstractMutator
    Why does it say the signature of the abstract method is apply(Individual<Integer>) if I have typed the superclass as StringIndividual<Integer>?
    Thanks.

    Yes, but the abstract method takes an arg of type <T extends Individual>. So it takes an Individual or a subclass thereof, depending on how I parameterise the class, right? StringIndividual is a subclass of Individual. So if I specify T to be StringIndividual, doesn't the method then take an arg of type StringIndividual?

  • Abstract Class Compiling Problem

    This is my first time using the code tags, I apologize if I didn't do it right.
    I can't seem to get the subclass to compile properly. I have defined an abstract class TemplateLoginCommand that encapsulates all of the login functionality. I have defined two abstract classes success and failure that should hold the code to forward the app to the right page on success, or handle any errors on login. I keep getting the following error message when I try to compile KlLoginCommand:
    I am removing the package info so my boss doesn't flip
    ../command/KlLoginCommand.java [17:1] ../command.KlLoginCommand should be declared abstract; it does not define failure() in ../.command.TemplateLoginCommand
    public class KlLoginCommand extends TemplateLoginCommand
    ^
    1 error
    Can anyone see what I am doing wrong here. I don't have a lot of experience with abstract classess/methods. Thanks
    public abstract class TemplateLoginCommand extends PageVerificationCommand implements Constants
        // Required Form Fields
        public static final String[] REQUIRED_FIELDS = {USERNAME, PASSWORD};
        // Abstract Methods Must Be Subclasses
        abstract void success(UserEntity entity);
        abstract void failure();
        /** Creates new TemplateLoginCommand */
        public TemplateLoginCommand()
            super();
        public TemplateLoginCommand(String childDirectory)
            super(childDirectory);
        public void destroy(Map map) throws Exception
            super.destroy(map);
            // Validate
            if (verifyFields(REQUIRED_FIELDS, map))
                // Attempt login
                try
                    String username = (String) map.get(USERNAME);
                    String password = (String) map.get(PASSWORD);
                    UserEntity user = UserEntity.login(username, password);
                    // Forward to rolemenu
                    success(user);
                    return;
                catch( SQLException sqle )
                    failure();
                    return;
            else
                failure();
                return;
    public final class KlLoginCommand extends TemplateLoginCommand
        /** Creates a new instance of KlLoginCommand */
        public KlLoginCommand()
        protected void failure()
        protected void success(UserEntity entity)
    }

    Hi,
    Try making the methods
    // Abstract Methods Must Be Subclasses
    abstract void success(UserEntity entity);
    abstract void failure();
    protected.
    Roger

  • Problems implementing abstract classes

    hello.
    this is james mcfadden. I am developing a multiplayer BlackJack card game in Java. the game consists of three programs: BlackJack.java, BlackJackServer.java and BlackJackClient.java (three 3 programs are shown below). i don't know how to implement abstract classes. i am trying to get the BlackJack.java program working with the BlackJackServer.java program. there should be "extends BlackJackServer" somewhere in the BlackJack.java program, but i don't know where.
    import javax.swing.*;
    public class BlackJack extends JPanel{
       public BlackJack(){
          //FlowLayout is default layout manager for a JPanel
          add(new JButton("Hit"));
          add(new JButton("Stay"));
          add(new JButton("New Game"));
       public static void main(String[] args){
          JFrame frame=new JFrame("BlackJack");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(500,500);
          frame.setLocation(200,200);
          BlackJack bj=new BlackJack();
          frame.setContentPane(bj);
          frame.setVisible(true);
    import java.io.*;//Provides for system input and output through data streams, serialization and the file system
    import java.net.*;//Provides the classes for implementing networking applications
    import java.util.*;//Contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes
    import java.awt.*;//Contains all of the classes for creating user interfaces and for painting graphics and images
    import javax.swing.*;//Provides a set of lightweight components that, to the maximum degree possible, work the same on all platforms
    public class BlackJackServer extends JFrame{
       private JTextArea jta=new JTextArea();//a text area for displaying text
       public static void main(String[] args){  
              new BlackJackServer();//invokes the constructor BlackJackServer()
       }//end main
       public BlackJackServer(){
          setLayout(new BorderLayout());//places the text area on the frame
          add(new JScrollPane(jta),BorderLayout.CENTER);//lays out a text area, arranging and resizing its components to fit in the centre region;and provides a scrollable view of a lightweight component
          setTitle("BlackJack Server");//Sets the title for this frame to the specified string
          setSize(500,300);//Resizes this component so that it has a width and a height
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Sets the operation that will happen by default when the user closes this frame
          setVisible(true);//shows the frame
          try{
             ServerSocket serverSocket=new ServerSocket(8000);//creates a server socket
             jta.append("Server started at "+new Date()+'\n');//displays the current date in the text area
             Socket socket=serverSocket.accept();//listens for a connection request
             DataInputStream inputFromClient=new DataInputStream(socket.getInputStream());//creates a data input stream
             DataOutputStream outputToClient=new DataOutputStream(socket.getOutputStream());//creates a data output stream
             while(true){
                float bet=inputFromClient.readFloat();//receives bet from the client
                float doublebet=bet+bet;//computes double the bet
                outputToClient.writeFloat(doublebet);//sends double the bet back to the client
                jta.append("Bet received from client: "+bet+'\n');//displays the bet in the text area
                jta.append("Double the bet found: "+doublebet+'\n');//displays double the bet in the text area
             }//end while
          }//end try
          catch(IOException ex){
             System.err.println(ex);//displays an error message
          }//end catch
       }//end constructor
    }//end class BlackJackServer
    import java.io.*;//Provides for system input and output through data streams, serialization and the file system
    import java.net.*;//Provides the classes for implementing networking applications
    import java.awt.*;//Contains all of the classes for creating user interfaces and for painting graphics and images
    import java.awt.event.*;//Provides interfaces and classes for dealing with different types of events fired by AWT components
    import javax.swing.*;//Provides a set of lightweight components that, to the maximum degree possible, work the same on all platforms
    public class BlackJackClient extends JFrame{
       private JTextField jtf=new JTextField();//a text field for receiving text
       private JTextArea jta=new JTextArea();//a text area for displaying text
       private DataOutputStream toServer;//output stream
       private DataInputStream fromServer;//input stream
       public static void main(String[] args){
          new BlackJackClient();//invokes the constructor BlackJackClient()
       public BlackJackClient(){
          JPanel p=new JPanel();//holds the label and text field
          p.setLayout(new BorderLayout());//sets the layout of the content pane of this component by default
          p.add(new JLabel("Enter bet"),BorderLayout.WEST);//displays the bet and lays out a JLabel, arranging and resizing its components to fit in the western region
          p.add(jtf,BorderLayout.CENTER);//lays out the text field, arranging and resizing its components to fit in the centre region
          jtf.setHorizontalAlignment(JTextField.RIGHT);//Sets the horizontal alignment of the text to the right
          setLayout(new BorderLayout());//places the text area on the frame
          add(p,BorderLayout.NORTH);//lays out the text field, arranging and resizing its components to fit in the northern region
          add(new JScrollPane(jta),BorderLayout.CENTER);//lays out a text area, arranging and resizing its components to fit in the centre region;and provides a scrollable view of a lightweight component
          jtf.addActionListener(new ButtonListener());//invokes the ButtonListener class
          setTitle("BlackJack Client");//Sets the title for this frame to the specified string
          setSize(500,300);//Resizes this component so that it has a width and a height
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Sets the operation that will happen by default when the user closes this frame
          setVisible(true);//shows the frame
          try{
             Socket socket=new Socket("localhost",8000);//creates a socket to connect to the server
             fromServer=new DataInputStream(socket.getInputStream());//creates an input stream to receive data from the server
             toServer=new DataOutputStream(socket.getOutputStream());//creates an output stream to send data to the server
          }//end try
          catch(IOException ex){
             jta.append(ex.toString()+'\n');//displays an error message
          }//end catch
       private class ButtonListener implements ActionListener{
          public void actionPerformed(ActionEvent e){
             try{
                float bet=Float.parseFloat(jtf.getText().trim());//gets the bet from the text field
                toServer.writeFloat(bet);//Converts the float argument to an int using the floatToIntBits method in class Float, and then writes that int value to the underlying output stream
                toServer.flush();//Flushes this output stream and forces any buffered output bytes to be written out
                float doublebet=fromServer.readFloat();//gets double the bet from the server
                jta.append("Bet is "+bet+"\n");//displays the bet in the text area
                jta.append("Double the bet received from the server is "+doublebet+'\n');//displays double the bet in the text area
             }//end try
             catch(IOException ex){
                System.err.println(ex);//displays an error message
             }//end catch
          }//end method
       }//end class
    }//end class BlackJackClient

    there should be "extends BlackJackServer" somewhere in the BlackJack.java programI very much doubt that.
    It's possible you might need to create a BlackJackServer object or something like that. But I don't see the point in subclassing it.

  • Problems with abstract classes

    I'm reading Java Wireless Blueprints and i'm confused with the functionality of abstract classes, especially in the next section:
    public byte[] getPoster() throws ApplicationException {
    if (poster == null) {
    try {
    poster =
    ModelObjectLoader.getInstance().getMoviePoster(primaryKey);
    } catch (ModelException me) {
    throw new ApplicationException();
    return poster;
    This class invoque to the ModelObjectLoader class that is abstract and after invoque getInstance().getMoviePoster(primaryKey); method. The source code of the class is:
    public abstract class ModelObjectLoader {
    private static ModelObjectLoader instance = null;
    protected ModelObjectLoader() {
    instance = this;
    return;
    public static ModelObjectLoader getInstance() {
    return instance;
    public abstract TheaterSchedule getTheaterSchedule(Theater theater)
    throws ModelException, ApplicationException;
    public abstract Movie getMovie(String movieKey)
    throws ModelException, ApplicationException;
    public abstract Movie getMovie(Movie movie)
    throws ModelException, ApplicationException;
    public abstract byte[] getMoviePoster(String movieKey)
    throws ModelException, ApplicationException;
    public abstract int[][] getMovieShowTimes(String theaterKey, String movieKey)
    throws ModelException, ApplicationException;
    public abstract SeatingPlan getSeatingPlan(String theaterKey,
    String movieKey,
    int[] showTime) throws ModelException,
    ApplicationException;
    I don�t find where is the implementation of the getMoviePoster(primaryKey) method.
    Can you help me to understand.
    Thanks

    public abstract byte[] getMoviePoster(String movieKey)It's an abstract method, which means that any concrete class that extends ModelObjectLoader must implement the method. If you really need to know (you might not), then call getInstance() and output the result of getClass().getName() on that object. That will tell you its type, and then you can go look at the source.

  • Implement abstract method from base class problem

    Here is the example:
    public abstract class AbstractClass{
    protected double aVariable;
    protected abstract double abstractMethod();
    public class RealClass extends AbstractClass{
    public double abstractMethod(){
    return aVariable;
    Error message:
    RealClass should be declared abstract; it does not define abstractMethod() in AbstractClass

    I also compiled the code with Jdk1.3 and it
    worked.. The code would not have compiled
    if the access modifier in the derived class
    was more restrictive(eg private )...

  • Object oriented design problem concerning abstract classes and interfaces

    I have an abstract class (class A) that takes care of database connections. It cannot be made into an interface as other classes extend it and all these other classes require the functionality in the methods it has (i.e. I cannot make all the methods abstract and then make this class an interface).
    I have a class that contains data (Customer class) that I will create from the data I extract from the database. This class will also be created by the User and submitted to the database portion of the program. The Customer class has functionality in its methods which is required by the rest of the program (i.e. I cannot make all the methods abstract and then make this class an interface).
    I have a factory class (CustomerFactory) that extends the Customer class. This has been created to restrict access to the creation and manipulation of Customers.
    I have a class (DatabaseQuery) that extends class A. But now that I have retrieved all of the information that comprises a Customer from the database, I cannot construct a Customer without making reference to UserFactory. But UserFactory is a class that I don't want the database portion of the program to know about.
    What I would like to do is have my DatabaseQuery class extend both Customer class and A class. But they are both classes and Java won't allow that.
    I can't make either of the two classes that I want to make parents of DatabaseQuery into interfaces... so what can I do other than just keep a reference to UserFactory in my DatabaseQuery class?
    Thanks,
    Tim

    >
    What I would like to do is have my DatabaseQuery class
    extend both Customer class and A class. But they are
    both classes and Java won't allow that.
    I can't make either of the two classes that I want to
    make parents of DatabaseQuery into interfaces... so
    what can I do other than just keep a reference to
    UserFactory in my DatabaseQuery class?Just a guess...
    The description sounds a little vague but it sounds like the correct solution would be to refactor everything. The first clue is when I see "database connection" as an "abstract class". The only hierarchy that a database connection might exist in is in a connection pool and even that is probably shaky. It should never be part of data records, which is what your description sounds like.
    That probably isn't what you want to hear.
    The other solution, which is why refactoring is better (and which also makes it apparent why the original design is wrong) is to create an entire other hierarchy that mirrors your current data hierarchy and wraps it. So you now have "Customer", you will now have "Customer" and "DBCustomer". And all the code that currently uses "Customer" will have to start using DBCustomer. Actually it is easier than that since you can simply make the new class be "Customer" and rename the old class to "DBCustomer". Naturally that means the new class will have to have all of the functionality of the old class. Fortunately you can use the old class to do that. (But I would guess that isn't going to be easy.)

  • Problem heriting fro abstract class

    Hi, i try to use abstract classes for the first time, i write this code:
    public abstract class ClassA{
    abstract void getValue();
    public lass ClassB extends ClassA{
    void getValue(){
    }But when i compile i get this message: ClassB must be abstract, it does not implements ClassA. What is wrong please?

    Should not a method called getValue() return a value?
    The following compiles
    // In a file called ClassA.java
    public abstract class ClassA {
        public abstract int getValue();
    // In a file called ClassB.java
    public class ClassB extends ClassA {
        private int value;
        public void getValue() {
            return value;
    }If your abstract class has only abstract methods and you don't need the method to be package-private scope. You can just use an interface.
    // In a file called InterfaceA.java
    public interface InterfaceA {
        public int getValue();
    // In a file called ClassB.java
    public class ClassB implements InterfaceA {
        private int value;
        public void getValue() {
            return value;

  • Abstract class with set and get methods

    hi
    how to write set and get methods(plain methods) in an abstartc class
    ex: setUsername(String)
    String getUsername()
    and one class is extending this abstract class and same methods existing in that sub class also..... how to write......plz provide some ideas
    am new to programming....
    asap
    thnx in advance

    yes... as i told u.... i am new to coding......
    and my problem is ..... i have 2 classes one is abstract class without abstract methods.. and another class is extending abstract class.....
    in abstract class i have 2 methods...one is setusername(string) and getusername() ..... how to write these two methods.... in abstract class i have private variables username...... when user logins ..... i need to catch the user name and i need to validate with my oracle database and i need to identify the role of that user and based on role of that user i need to direct him to appropriate jsp page.......
    for that now i am writing business process classes..... the above mentioned two classes are from business process.....
    could u help me now
    thnx in advance

  • Implementing Comparable in an abstract class

    Hi all,
    I am making my first sortie with abstract classes. I have had a good look around, but would still appreciate some advice with the following problem.
    In my application I have several classes that have many things in common. I have concluded therefore, that if I create and then inherit from an abstract super class, I can reduce and improve my code. I created this abstract class:
    public abstract class YAbstractObject implements Comparable {
        public YAbstractObject(int projectId, YObject object, String objectName) {
            this.projectId = projectId; // Always the same parameters
            this.object = object;
            this.objectName = objectName;
        // This is abstract as it must always be present for sub classes but differant processing will take place
        public abstract void resolveObject();
        // These three methods will always be the same for all sub classes
        public String getName() {
            return objectName;
        public YObject getObject() {
            return object;
        public boolean isValid() {
            return isValid;
    // Overridden and always the same for all sub classes
        public String toString() {
            return objectName;
        // implemented abstract method
        public int compareTo(Object thatObject) {
            // Issue here! I would like something as follows:
            //  return this.getName().compareToIgnoreCase(thatObject.getName());
    // Variable decleration
        private int projectId;
        private YObject object;
        private String objectName;
        private boolean isValid;As I have commented in the compareTo() method, I would like it to be able to use the getName() method for comparison objects and compare them. But it does not like this, as it does not know that "thatObject" is of the same class as this object - I hope that made sense.
    in essence, I want to inherit this method for different classes and have it work with each.
    Is there a way to do this? Generics?
    Any observations, greatly appreciated,
    Steve

    You can use also generics (if applicable: java -version >= 1.5).
    public abstract class Test implements Comparable<Test> {
         String name;
         public Test(String name) {
              this.name = name;
         public String getName() {
              return name;
         public int compareTo(Test obj) {
              return this.getName().compareTo(obj.getName());
    public class Other extends Test {
         public Other(String name) {
              super(name);
    public class Tester extends Test {
         public Tester(String name) {
              super(name);
         public static void main(String[] args) {
              Test t = new Tester("t");
              Test a = new Tester("a");
              Test o = new Other("t");
              System.out.println(t.compareTo(a));
              System.out.println(t.compareTo(new Object())); //compile error
              System.out.println(t.compareTo(o));
    }Without the compile error line it will give the following result:
    19
    0

  • Abstract class initialisation

    Hi,
    I have the following problem. What do you suggest?
    I have an interface A, abstract class B, B's subclasses C and D, and mainClass
    interface A
    abstract class B implements A {
        B b;
        public B(String desc)
         if (desc.equals("C")) b=new C();
         else if (desc.equals("D")) b=new D();
    class C extends {
      public C() {}
    class D extends {
      public D() {}
    class mainClass{
      B b=new B("C"); // but B can not be initiated
    }B is an abstract class and can not be initiated, I can not define B as normal class, because in B, I define some abstract methods
    and want all its subclasses to define them.
    What do you suggest me for enhancement?

    Hi duffymo,
    Your answer quite intersting, can you provide some concrete example!
    Do you mean like this:
    interface A
    class B implements A{
    B b;
    public B(String desc) {
    b=Class.newInstance(desc);
    class C extends B
    class main {
    B=new B(desc);
    It seems quite okey, but the problem is that I want subclasses (C and D) to impelement some certain methods. Thus I though B as abstract class
    It's called a Factory class or virtual constructor -
    that's how you create different runtime types. It's a
    GOF Pattern - read about it.
    I wouldn't build all that stuff into the abstract B
    constructor. That'll force you to modify the B class
    every time you add a new subtype - that's not a good
    idea. Move that code out into a separate class named
    AFactory and give it a static method that does that
    creation stuff for you. I know - "That just moves the
    changes out of B and into the AFactory" - yes, but I
    think that's where they belong.
    The java.lang.Class class has a factory method built
    into it already - newInstance(). You can use that to
    instantiate different subclasses:
    A newInstance = Class.newInstance("C");
    A anotherInstance = Class.newInstance("D");That's the way I'd do it. - MOD

  • Abstract class confusion

    I am writing a J2ME application, and I want to write a Record management system (RMS) that I can use in other J2ME programs. I have a Record class that RMS classes need to know about. The idea is that the Record class is abstract, and the implementation is defined by a subclass - depending on what the application needs to store. Any Record must provide the following:
    1) A constructor which takes a single byte[] parameter, which is the data read in from the RecordStore by the RMS. The implementation depends on what information is stored in this type of Record - it might be a String, series of ints, etc...
    2) A method getStorageFormat() which returns a btye[] representing the data to be stored in the RecordStore. Again, this is dependent on the application.
    I think that I have to use an abstract class here, so I have written an abstract class called Record - here's what it looks like:
    public abstract class Record {
         public Record(byte[] bytes) { }; //Should this be an empty constructor?
         public abstract byte[] getStorageFormat();
    }My problem is that I can't define a subclass of Record that works! Here's an example:
    public class MyRecord extends Record {
           String data1, data2, data3; //Some data that is stored in this record
           public MyRecord(byte[] bytes) {
                  String data = new String(bytes);
                  // do some processing to extract the data...
           public byte[] getStorageFormat() {
                  String sep = ","; //A seperator
                  String tmp = data1 + sep + data2 + sep + data3; //put all the data together with
                  return tmp.getBytes();
    }}I get an error in Eclipse with the MyRecord constructor that says:" The implicit super constructor Record() is undefined. Must explicity invoke another constructor". I tried super() but I get the same error. Can anyone please tell me what I am doing wrong? It seems to me that I am misunderstanding something about how abstract classes work.

    Because you defined a ctor that takes args, the implicit one that takes no args--super()--is no longer implicitly supplied. You have to either put a no-arg ctor into the parent class, or call the one that you already have.
    public Record(byte[] bytes) { }; //Should this be an empty constructor?
    public abstract byte[] getStorageFormat();
    }No. You don't want a ctor that takes args and does nothing. If you're taking that arg, then you should use it to initialize the state of the object.
    Here are the rules for constructors--"ctors" because I'm lazy. Also, because I'm lazy, "super(...)" and "this(...)" mean any super or this call, regardless of how many args it takes, including those that take no args.
    1) Every class has at least one ctor.
    1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
    1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a
    public MyClass() {...}
    if you want one.
    1.3) Constructors are not inherited.
    2) The first statement in the body of any ctor is either a call to a superclass ctor
    super(...)
    or a call to another ctor of this class
    this(...)
    2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor
    super()
    as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
    2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.

  • Extend abstract class & implement interface, different return type methods

    abstract class X
    public abstract String method();
    interface Y
    public void method();
    class Z extends X implements Y
      // Compiler error, If I don't implement both methods
      // If I implement only one method, compiler error is thrown for not
      // implementing another method
      // If I implement both the methods,duplicate method error is thrown by 
      //compiler
    The same problem can occur if both methods throw different checked exceptions,or if access modifiers are different..etc
    I'm preparing for SCJP, So just had this weired thought. Please let me know
    if there is a way to solve this.

    Nothing you can do about it except for changing the design.
    Kaj

  • Abstract Class and polymorphism - class diagram

    Hi,
    ]Im trying to draw a class diagram for my overall system but im not too sure how to deal with classes derived from abstract classes. I'll explain my problem using the classic shape inheritance senario...
    myClass has a member of type Shape, but when the program is running shape gets instantiated to a circle, square or triangle for example -
    Shape s = new circle();
    since they are shapes. But at no stage is the class Shape instantiated.
    I then call things like s.Area();
    On my class diagram should there be any lines going from myClass directly to circle or triangle, or should a line just be joining myClass to Shape class?
    BTW - is s.Area() polymorphism?
    Thanks,
    Conor.

    Sorry, my drawing did not display very well.
    If you have MyClass, and it has a class variable of type Shape, and the class is responsible for creating MyClass, use Composition on your UML diagram to link Shape and MyClass.
    If you have MyClass, and it has a class variable of type Shape, and the class is created elsewhere, use Aggregation on your UML diagram to link Shape and MyClass.
    If you have MyClass, and it is used in method signatures, but it is not a class variable, use Depedency on your UML diagram to link Shape and MyClass. The arrow will point to Shape.
    Shape and instances of Circle, Triangle, Square, etc. will be linked using a Generalization on your UML diagram. The arrow will always point to Shape.
    Anything that is abstract (class, method, variable, etc.) should be italicized. Concrete items (same list) should be formatted normally.
    BTW, the distinction between Composition, Aggregation and Dependency will vary from project to project or class to class. It's a gray area. Just be consistent or follow whatever guidelines have been established.
    - Saish

Maybe you are looking for

  • Donot find user id 50001 in the HSP_USERS table

    Hi All, I am using EPM 11.1.1.1.0 and want to import a planning application. In one of the threads i read that you need to keep a backup of SID from HSP_USERS table in the schema where the USER)iD = 50001. But i donot have a record in the HSP_USERS t

  • Complex values cannot be converted to ....

    Hi; I have an odd problem I can't seem to figure out....I wrote a couple of neat little functions to create boolean selects, populate them with the values from a database and "select" the correct one inthe html form. <cffunction name="booleanSelect"

  • Need to delete my community forum account

    I want to delete my account. I have tried to follow some of the forum managers but no one will accept it. Can some please help?

  • How to Make BB Torch a Hotspot

    Is there a way for me to make my Torch a hotspot? I have a mobile share plan and could remove my tablets completely if my Torch could give them access to internet. 

  • Installazione adobe creative cloud per desktop.

    salve ho un mac versione 10.10 sto cercando di installare la creative cloud per desktop ma a metà installazione si blocca e si chiude la finestra di installazione senza nessun avviso. Perché? come posso risolvere qst problema?