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

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

  • Abstract class hierarchy - compilation error

    I coded an abstract class and couple of concrete classes. When I am compiling the concrete classes, I see the error message: cannot find symbol abstract class. For diagnosing I coded very simple programs AbstractClass1.java and ConcreteClass.java. Again I am facing the same compilation error. Code is given below:
    abstract class AbstractClass1 {
    protected AbstractClass1() {
    System.out.println("AbstractClass1 constructor called");
    public abstract void distinct_method();
    public void common_method() {
    System.out.println("common method called");
    distinct_method();
    class ConcreteClass extends AbstractClass1 {
    public void distinct_method() {
    System.out.println("distinct_method called");
    I can't figure out what's causing the compilation error.
    Edited by: ague on Nov 9, 2008 5:52 PM

    Yes. AbstractClass1 is defined in AbstractClass1.java. I know it is compiling fine for others. I am unable to figure out the problem at my end because the problem was first encountered with a different (and bigger) program. I then started using new simpler classes to zero in on the problem area. I copied the code from java forum so I know it can't be a problem with code. You and one more person confirmed it. In my first post I was focusing on abstract class because the problem started when I began coding a hierarchy with an abstract class at the top. Other programs are working fine. Thanks anyway.

  • Abstract/ concrete class questions/problems

    I am new to java and working on a abstract problem. I'm getting several errors. Here is the code I have so far for the abstract class. I commented out the super and it compiles but I'm not sure if it correct. I'm suppose to create a abstract base class Animal. Single constructor requires String to indicate type of animal which then is stored in an instance variable. I also have to add a few methods (describe(), move(), etc).
    public abstract class  Animal
         public Animal(String type)
              //super(type);
         public abstract String describe();
         public abstract String sound();
         public abstract String sleep();
         public abstract String move();
    }

    thanks for the replies. I modified my code but I have a few more errors I can't figure out. Can you browse the code and help point me in the right direction.
    Here are the errors I get
    cannot find symbol
    symbol : constructor Cat(java.lang.String,java.lang.String)
    location: class Cat
    cannot find symbol
    symbol : constructor Robin(java.lang.String)
    location: class Robin
    abstract base class:
    public abstract class  Animal
         String type;
         public Animal(String type)
           this.type = type;
         public abstract String describe();
         public abstract String sound();
         public abstract String sleep();
         public abstract String move();
    }concrete class
    public class Cat extends Animal
         private String name;
         protected String breed;
         public Cat()
           super("Cat");
         public String describe()
              return new String(",a breed of Cat called");
         public String sound()
              return new String("Meow");
         public String sleep()
              return new String("Kitty is having purfect dreams!");
         public String move()
              return new String("This little Kitty moves fast!");
    }another abstract class
    public abstract class Bird extends Animal
         protected String breed;
         public Bird()
           super("Bird");
         public abstract String move();
    }here is the abstract test program itself
    public class AbstractTest
         public static void main(String[] args)
              Cat cat = new Cat("Kitty", "Angora");
              Robin bird = new Robin("Rockin");
              System.out.println("Form the cat:   ");
              System.out.print("This is:     "); cat.describe();
              System.out.print("Sound:       "); cat.sound();
              System.out.print("Sleeping:    "); cat.sleep();
              System.out.print("Moving:      "); cat.move();
              System.out.println("\n");
              System.out.println("For the robin:     "); bird.describe();
              System.out.print("This is:             "); bird.sound();
              System.out.print("Sound:               "); bird.sleep();
              System.out.print("Moving:              "); bird.move();
              System.out.print("\n");
              System.out.println("nEnd of program.");
    }

  • 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?

  • 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;

  • 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.

  • Compilation problem -- classes in same package

    I feel like I should know the answer to this, but since I can't figure it out, I'll ask it anyway. I have the following three classes, all in the same package. The Dog class compiles just fine. As for the other two, the compiler insists it "cannot find symbol" when it comes to Dog. Can anyone help?
    package com.example;
    public class Dog {
        private String breed;
        public Dog(String breed) {
             this.breed = breed;
        public String getBreed() {
             return breed;
    package com.example;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class ListenerTester extends HttpServlet {
        public void doGet (HttpServletRequest request, HttpServletResponse response)
                       throws IOException, ServletException {
             response.setContentType("text/html");
             PrintWriter out = response.getWriter();
             out.println("test context attributes set by listener<br>");
             out.println("<br>");
             Dog dog = (Dog) getServletContext().getAttribute("dog");
             out.println("Dog's breed is: " + dog.getBreed());
    package com.example;
    import javax.servlet.*;
    public class MyServletContextListener implements ServletContextListener {
        public void contextInitialized(ServletContextEvent event) {
              ServletContext sc = event.getServletContext();
              String dogBreed = sc.getInitParameter("breed");
              Dog d = new Dog(dogBreed);
              sc.setAttribute("dog", d);
        public void contextDestroyed(ServletContextEvent event) {
    }

    Ok, your .java files and .class files are in the correct location.
    What you should have done is:
    1.) Go to C:\tomcat\web-apps\listenerTest\WEB-INF\classes
    2.) compile your program using "javac -cp c:\tomcat\lib\servlet-api.jar;. com/example/*.java" (note the "." on the classpath, which tells java to include the current directory on its classpath).
    It would also be a good idea to have a sparate tree for the sources and the classes.
    And to develop your application independently from the deployment target.
    But those are semi-advanced topics that you could ignore for now.
    Edit: and again: there's nothing wrong with having classpath trouble when starting Java. But it means that you still have to learn some basics, before you should attempt any J2EE development. Seriously, don't do that yet.

  • 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.)

  • 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 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

  • Instanciate generic subclass of an abstract class

    Hello,
    I'm writing a litle file manager API for my application, organised like a Database: a table filled by records.
    I want my table to be able to be able to manage different types of records (but one record type by table!), so I have this hierarchy:
    the abstract record class:
    public abstract class Record {
         public Record() {
         public abstract void readFrom(DataInput in, int length) throws IOException;
         public abstract void writeTo(DataOutput out) throws IOException;
         public abstract int prepareToWrite();
    }the abstract atomic record class, extending the abstract record class:
    public abstract class AtomicRecord<T> extends Record {
         public AtomicRecord() {
         public AtomicRecord(T value) {
              super();
         public abstract T getValue();
         public abstract void setValue(T value);     
    }and, for example, the StringRecord class:
    public class StringRecord extends AtomicRecord<String> {
         code doesn't matter.
    }now, I want to make a table of generic records:
    public class RandomRecordAccessAppendableFileTable<RecordType extends Record>{
         public final RecordType getRecord(long id) throws IOException {
              RecordType record = new RecordType();
    }problem: the RecordType is obviously not instanciable, as it extends Record, and not StringRecord. But I still want to instanciate a new StringRecord from a RandomRecordAccessAppendableFileTable<StringRecord> and a FooRecord from a RandomRecordAccessAppendableFileTable<FooRecord>.
    Is there a way I can do this?
    Thank you in advance.

    This is just my opinion, so you might ignore it: The design you are targeting is a result of misunderstanding what Generics are for and what Generics may provide in their current state. Their only purpose is to provide compile-time type safety. Creating instances the way you want to do seems more runtime focused, i.e., when generic information is gone.
    Maybe, you should consider passing a factory at construction time that enables to create a record of a specific type. Using the class object requires reflection, which will introduce implicit contracts to record classes and potential runtime failures.

  • Access overriden method of an abstract class

    class Abstract
    abstract void abstractMethod(); //Abstract Method
    void get()
    System.out.print("Hello");
    class Subclass extends Abstract
    void abstractMethod()
    System.out.print("Abstract Method implementation");
    void get()
    System.out.print("Hiiii");
    In the above code, i have an abstract class called "Abstract", which has an abstract method named "abstractMethod()" and another method called "get()".
    Now, this class is extended by "Subclass", it provides implementation for "abstractMethod()", and also overrides the "get()" method.
    Now my problem is that i want to access the "get()" method of "Abstract" class. Since it is an abstract class, i cant create an object of it directly, and if i create an object like this:
    Abstract obj = new Subclass();
    then, obj.get() will call the get() method of Subclass, but how do i call the get() method of Abstract class.
    Thanks in advance

    hey thanks a lot,, i have another doubt regarding Abstract classes.
    i was just trying something, in the process, i noticed that i created an abstract class which does not have any abstract method, it gave no compilation errors. was wondering how come this is possible, and what purpose does it solve?

Maybe you are looking for

  • Getting FLV to stop playing when user clicks on nav button

    I have a portfolio_mc that is inside of a content_mc (stage->content_mc->portfolio_mc). There are 3 buttons that take the user to an appropriate frame designated by a frame label and this loads up an FLV. The problem is that when I click on any of th

  • Payment to Vendor by bank transfer with out useing APP

    Dear all, I of our Client has issue-- that i want post a wire transfer to vendor with out using APP. thanks & regards krishna reddy

  • Creating a PDF from a secure website

    I am attempting to create a PDF from a page within a secure website, which is successful, however the content on the page turns into random symbols.  Could this be due to encryption on the site ?

  • Error Message B200 for Canon Pixma MG5320

    I have an error message B200 on my Pixma MG5320 that says "Unplug power cord and contact service center."  I'm more than 100 miles from my nearest Canon service center.  Any fix for this error message other than to buy a new printer?  With the price

  • Unable to full text index the contents in Oracle 11g UCM

    Hi, I am new to the Oracle UCM 11g. i am unable to full text index the content files that are check-in into the Oracle UCM. I have added the below entries in config.cfg file: SearchIndexerEngineName=OracleTextSearch IndexerDatabaseProviderName= Syste