1 2 Previous Next 15 Replies Latest reply: May 2, 2007 12:11 AM by 807599 RSS

    abstract classes

    807599
      Is there any way to get the System.out lines to print and keep the class abstract?
      /*
       * Employee.java
       *
       * Created on April 30, 2007, 11:54 PM
       *
       * To change this template, choose Tools | Template Manager
       * and open the template in the editor.
       */
      
      /**
       *
       * @author Pete Berardi
       */
      import java.util.Scanner;
      
          
          /** Creates a new instance of Employee */
      
      
      public abstract class Employee extends Object
      {
          protected String EmpName;
         
          protected String EmpAddress;
          protected String EmpSsn;
          protected String EmpEmployeeID;
          protected double EmpYearlySalary;
          protected double computePay;
         
          
        
           public Employee() {// you had this below the Employee class, it should be inside
                              // the class.
          }
          /** Creates a new instance of Employee */
          public Employee(String name, String address, String ssn, 
                  String id, double ysalary, double pay)
          {
            EmpName = name;
            System.out.println("EmpName has been constructed");
            EmpAddress = address;
            System.out.println("EmpAddress has been constructed");
            EmpSsn = ssn;
            System.out.println("EmpSsn has been constructed");
            EmpEmployeeID = id;
            System.out.println("EmpEmployeeID has been constructed");
            EmpYearlySalary = ysalary;
            System.out.println("EmpYearlySalary has been constructed");
            computePay = pay;
            System.out.println("computePay has been constructed");
           }
          public void setEmpName(String name)
          {
              EmpName = name;
           
          }
          public String getEmpName()
          {
              return EmpName;
          }
          
          public void setEmpAdress(String address)
          {
              EmpAddress = address;
              
          }
          public String getEmpAddress()
          {
              return EmpAddress;
          }
          public void setEmpSsn(String ssn)
          {
               EmpSsn = ssn;  
              
          }
          public String getEmpSsn()
          {
              return EmpSsn;
          }
          public void setEmpID(String id)
          {
              EmpEmployeeID = id;
              
          }
          public String getEmployeeID()
          {
              return EmpEmployeeID;
          }
          public void setEmpYearlySalary(double ysalary)
          {
              EmpYearlySalary = ysalary;
          }
          public double getEmpYearlySalary()
          {
              return EmpYearlySalary;
          }
          public void setcomputePay(double pay)
          {
              computePay = pay;
              
          }
          public double computePay()
          {
              return computePay;
          }
           
          
         public static void main( String args[])
          {
            // You need to put your calls to create the objects in hear.
            // Hope this helps.
            
            
               
          }
              
         
          
      }
      
         
          
        • 1. Re: abstract classes
          807599
          You don't need to extend Object, this is implicit.

          Your class is not abstract.

          What the heck has System.out got to do if a class is abstract or not?
          • 2. Re: abstract classes
            807599
            Sorry, then why dont the lines print?
            • 3. Re: abstract classes
              807599
              Probably because your main method has nothing but comments in it. Try declaring and instantiating an actual object.
              • 4. Re: abstract classes
                807599
                Could you please give me an example?
                • 5. Re: abstract classes
                  807599
                  Just a couple of things..
                  /**
                  *
                  * @author snip
                  */
                  Might wanna not post your real name online (assuming this IS your real name)..
                  /** Creates a new instance of Employee */
                  public abstract class Employee extends Object
                  {
                  protected String EmpName;
                  snip This doesn't create an instance of Employee ... it starts the definition of what an Employee is.
                  /** Creates a new instance of Employee */
                  public Employee(String name, String address,
                  String ssn,
                  snip Again, this doesn't create an instance of Employee ... it defines what happens to the data WHEN an instance is created.. (That's what constructors do ... provide initialization routines for objects as they're created)

                  The correct way to create an instance of an object is thusly:
                  <object type> <name> = new <object type>();
                  example..
                  Employee Pete = new Employee( <data in here that goes for the constructor> );
                  It's up to you to create an instance of the object in a correct spot. (For this program, I'd say in the main method)
                  • 6. Re: abstract classes
                    807599
                    I thought you cant have that type of instantiation for an abstract class. Which brings up another question, why is my class NOT abstract?
                    • 7. Re: abstract classes
                      807599
                      Could you please give me an example?
                      You mean you have an assignment involving Objects and you haven't covered them in the course yet?
                      • 8. Re: abstract classes
                        807599
                        Well you can call your class abstract and leave it at that but if you removed the abstract keyword your code will still compile. The reason it isn't truly abstract is because none of the methods are abstract. Read about abstract classes in your text book
                        • 9. Re: abstract classes
                          807599
                          ive been reading til my eyes are bloodshot and i just dont understand where to put the call if i have an abstract method... a call for Employee cannot be invoked correct? My class must be abstract, its part of the assignment.
                          • 10. Re: abstract classes
                            807599
                            Well you might have to re-read you assignment and/or clarify with your teacher. How you use abstract classes is by having another concrete class that extends the abstract class and implements all the abstract methods. Then you can create an object of the subclass.
                            public abstract class Foo {
                                 // abstract method
                                public void method(); 
                            }
                            
                            public class Bar extends Foo {
                                // concrete method
                                public void method() {
                                    System.out.println("Hello");
                                }
                            }
                            Now you can create instances of Bar.
                            • 11. Re: abstract classes
                              807599
                              But i have to have a print statement after the constructor in Employee? Does that go in the so called Bar class or in the Employee class?
                              • 12. Re: abstract classes
                                807599
                                You can leave the print statements where they are as long as you have an appropriate super call in your subclass.

                                But this all sounds hinky to me. I think you should go see the teacher and don't give me any cr&#97;p about how useless he/she is.
                                • 13. Re: abstract classes
                                  807599
                                  You know flounder, I appreciate this forum. I think its great that people who have knowledge are willing to share this knowledge with others. However what I do not appreciate is a condescending attitude from people with knowledge. I do not feel that I am asking out of line questions. If you care not to help, then please stay out of the thread. For some reason I get the feeling that you need me to bow to you because of this vast knowledge that you have. This certainly is a "floundering" attitude.
                                  • 14. Re: abstract classes
                                    807599
                                    I wasn't implying you are asking out of the line questions, simply that I have no idea what your assignment is or what your teacher wants. Only he/she does so any advice or help you get here may be wrong if it is not what they want. So to find out what they really want, you need to ask them not us. Clear?

                                    As for the comment about saying your teacher is cr&#97;p is in response to most noobs who come here and blame their teachers. I was just stopping you from saying that beforehand.

                                    I am not giving you a hard time. If you think I was then you need to grow a thicker skin. Life gets a hell of a lot tougher than this.
                                    1 2 Previous Next