Generic classes and inheritance

I am in the midst of converting some database object code over to split the data from the database functionality, and I am coming into issues with generics.
I have three bean classes:
abstract public class Payment {
  // common fields and their get/set methods
public final class AU_Payment
extends Payment {
  // extra fields and their get/set methods
public final class US_Payment
extends Payment {
  // extra fields and their get/set methods
}The code to write these classes to the database used to be in those classes, now I am moving them out to their own classes. I need to have a similar hierarchy so I can obtain an instance of the right class (through a factory) to write these objects to the database.
public interface PaymentDB<T extends Payment> {
  public Result load(Connection conn, T payment, ResultInfo resultInfo) throws SQLException;
  public Result loadAll(Connection conn, List<T> allPayments, ResultInfo resultInfo) throws SQLException;
}If I have the code for the AU_PaymentDB as the following, it won't compile:
public class AU_PaymentDB<AU_Payment> {
  public Result load(Connection conn, AU_Payment  payment, ResultInfo resultInfo) throws SQLException {
    return null;
  public Result loadAll(Connection conn, List<AU_Payment> payment, ResultInfo resultInfo) throws SQLException {
    return null;
}the compiler complains that the class doesn't override the interface, and I need to recode it to the following to get it to compile:
public class AU_PaymentDB<AU_Payment> {
  public Result load(Connection conn, Payment  payment, ResultInfo resultInfo) throws SQLException {
    return null;
  public Result loadAll(Connection conn, List payment, ResultInfo resultInfo) throws SQLException {
    return null;
load now takes just a Payment in it's signature list, and loadAll takes an untyped List.
This means I can actually call load() with a US_Payment and it works fine, which I don't want. Also, I cannot add an AU_Payment to the list in loadAll, because the list is of the wrong type.
How do I fix this? I want the AU_PaymentDB class to only act upon AU_Payments, and I need the loadAll to be able to add new AU_Payments to the list that is passed in.
I hope this all makes sense,
Chris

ok, I'm assuming that you just forgot to paste in that AU_PaymentDB implements PaymentDB :-)
parameterize AU_PaymentDB as follows:
public class AU_PaymentDB implements PaymentDB<AU_Payment> {
  public Result load(Connection conn, AU_Payment payment, ResultInfo resultInfo) throws SQLException {
    return null;
  public Result loadAll(Connection conn, List<AU_Payment> payment, ResultInfo resultInfo) throws SQLException {
    return null;
}so the interface defines a looser parameter ( Payment ) and your implementation drills it down to more specifically AU_Payment
Bob, I believe, is your uncle

Similar Messages

  • Abstract classes and inheritance

    I'm trying to do some simple inheritance but I'm a little stuck. Without giving too much away here's what I have (or am trying to have). I have an abstract "Test" class and a number of concrete classes that extend that abstract class. In my main method I have an array of Test objects. Each object in the array is a certain kind of "Test" and each one has its own way of doing most things but it doesn't make sense to have just a plain Test object because it is an abstraction. In my code I go through the array and execute a method, runTest(), for each Test in the array. However, my abstract Test class doesn't have a runTest() method b/c it will never get used and java complains. At runtime shouldn't java figure out, OK this is TestA, so go to TestA's runTest method (polymorphism?). What should I put in my runTest method in the abstract class? I know I can put anything there but what is standard?

    JFactor2004 wrote:
    ... Each object in the array is a certain kind of "Test" and each one has its own way of doing most things but it doesn't make sense to have just a plain Test object because it is an abstraction. In my code I go through the array and execute a method, runTest(), for each Test in the array. However, my abstract Test class doesn't have a runTest() method b/c it will never get used and java complains. If you want to instantiate the Test class
    you need to provide an implementation for the runTest() method,
    something like/*type*/ runTest() { throw new UnsupportedOperationException(); }

  • About classes and Inheritance

    hi every one,
    i want use class with object in data block and i want know how i can use inheritance with objects.
    becouse i have interview in this two subjects, can any body support my.
    thanks,,,,,,,

    Hello,
    Start Forms Builder, the press F1 to display the online help.
    In the search tab, you can type "Class Property" or "Object Library" to find documentation on those topics:
    About Property Classes A property class is a named object that contains a list of properties and their settings. Once you create a property class you can base other objects on it. An object based on a property class can inherit the setting of any property in the class that makes sense for that object. Property class inheritance is an instance of subclassing. Conceptually, you can consider a property class as a universal subclassing parent. There can be any number of properties in a property class, and the properties in a class can apply to different types of objects. For example, a property class might contain some properties that are common to all types of items, some that apply only to text items, and some that apply only to check boxes. When you base an object on a property class, you have complete control over which properties the object should inherit from the class, and which should be overridden locally. Property classes are separate objects, and, as such, can be copied between modules as needed. Perhaps more importantly, property classes can be subclassed in any number of modules.
    or
    Using the Object Library These topics contain information about using the Object Library in Oracle Forms: About the Object Library Removing an Object from the Object Library Creating a tab in the Object Library Deleting a Tab in the Object Library Saving an Object in the Object Library Opening an Object Library Module Displaying the Object Library Closing the Object Library Commenting Objects in the Object Library
    Francois

  • Generic classes and the catch block

    Is there a reason why the catch block doesn't work with generic classes?

    JLS 8.1.2:
    <quote>
    It is a compile-time error if a generic class is a direct or indirect subclass of Throwable.
    </quote>
    <quote>
    This restriction is needed since the catch mechanism of the Java virtual machine works only with non-generic classes.
    </quote>
    I guess they didn't feel a need to tinker with the JVM definition to achieve that.
    Too slow!
    Message was edited by:
    DrLaszloJamf

  • Generic Collections and inheritance

    Hi all
    I have the following code:
    public class GenericTest {
         public static <T,C extends Collection<T>> C process(C collection){
              // do some stuff (using T)
              return collection; // just to make a complete methode
         public void main(String[] args){
              List<String> l1 = new ArrayList<String>();
              List<String> l2;
              l2 = process(l1); // does not compile
    }Compilation fails with message :
    Bound mismatch: The generic method process(C) of type GenericTest is not applicable for the arguments (List<String>) since the type List<String> is not a valid substitute for the bounded parameter <C extends Collection<T>>     
    My questions:
    why doesn't it work?
    How do I fix it?
    regards
    Spieler

    What Compiler are you using?
    Your code compiles just fine on the JDK 1.5 compiler (once I added an inport for java.util.*)
    If the error message is from your IDE, you should check your IDE's web site for an existing bug, and for assistance.
    This is not the correct forum since your code compiles on the SUN JDK.
    Bruce

  • Generic methods and inheritance

    Hello,
    I have a class structure like this:
    A - - - - > IA (A implements IA)
    C - - - - > IC -------> IB (C implements IC extends IB)
    In IA I have a method create that returns <T extends IB<T>>:
    public interface IA {
        public <T extends IB<T>> T create();
    }IB:
    public interface IB<T> {  
    }IC extends IB like this:
    public interface IC extends IB<IC> { 
    }C implements IC:
    public class C implements IC{
    }Finally the problem: I wan to implement A in order to return an IC in the create method:
    public class A implements IA{
        public IC create() {
            IC c = new C();
            return c;
    }This compiles but I get this warning: 'A.java uses unchecked or unsafe operations.'
    What is the proper way to create such a structure?
    Thanks,
    Miguel

    you can try giving more horrible things, like giving the class you want in the method params, like :
    create(Class<IB> clazz);and then use reflection to create the instance :
    clazz.getInstance();But it's quite heavy, I think...

  • Generic and Inheritance, how to use them together?

    Hi guys, I am trynig to design some components, and they will use both Generics and Inheritance.
    Basically I have a class
    public class GModel <C>{
        protected C data;
        public C getData(){return data;}
    }//And its subclass
    public class ABCModel <C> extends GModel{
    }//On my guess, when I do
    ABCModel abcModel = new ABCModel<MyObject>();The data attribute should be from MyObject type, is it right?
    So, usign the netbeans when I do
    MyObject obj = abcModel.getData();I should not use any casting, since the generics would tell that return object from getDta would be the MyObject.
    Is this right? If yes; did someone try to do that on netbeans?
    Thanks and Regards

    public class GModel <C>{
    public class ABCModel <C> extends GModel{public class ABCModel <C> extends GModel<C>{
    ABCModel abcModel = new ABCModel<MyObject>();ABCModel<MyObject> abcModel = new ABCModel<MyObject>();

  • Multiple inherited with generics classes

    Hello all, here is my generic observer/ subject code.
    package jstock;
    * @author yccheok
    public interface Observer<S, A> {
        public void update(S subject, A arg);
    public class Subject<S, A> {
        public void attach(Observer<S, A> observer) {
            observers.add(observer);
        void notify(S subject, A arg) {
            for (Observer<S, A> obs : observers) {
                obs.update(subject, arg);
        private List<Observer<S, A>> observers = new CopyOnWriteArrayList<Observer<S, A>>();
    }However, when I try to implements more than one class (single class only is ok), I get the following error :
    /home/yccheok/Projects/jstock/src/org/yccheok/jstock/gui/MainFrame.java:40: org.yccheok.jstock.engine.Observer cannot be inherited with different arguments: <org.yccheok.jstock.engine.RealTimeStockMonitor,java.util.List<org.yccheok.jstock.engine.Stock>> and <org.yccheok.jstock.engine.StockHistoryMonitor,org.yccheok.jstock.engine.StockHistoryServer>
    public class MainFrame extends javax.swing.JFrame implements
    Here is the code which I am implementing the generic classes.
    public class MainFrame extends javax.swing.JFrame implements
    org.yccheok.jstock.engine.Observer<RealTimeStockMonitor, java.util.List<org.yccheok.jstock.engine.Stock>>,
    org.yccheok.jstock.engine.Observer<StockHistoryMonitor, StockHistoryServer>
    May I know how I can avoid the error message?
    Thank you.
    cheok

    However, when I try to implements more than one classMore than one interface, you mean.
    May I know how I can avoid the error message?You can't implement a generic interface more than once.
    http://angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#Can%20a%20class%20implement%20different%20instantiations%20of%20the%20same%20parameterized%20interface?

  • Problem in generic value copier class / reflection and generic classes

    Hello experts,
    I try to archive the following and am struggling for quite some time now. Can someone please give an assessment if this is possible:
    I am trying to write a generic data copy method. It searches for all (parameterless) getter methods in the source object that have a corresponding setter method (with same name but prefixed by "set" instead of "get" and with exactly one parameter) in the destination object.
    For each pair I found I do the following: If the param of the setter type (T2) is assignable from the return type of the getter (T1), I just assign the value. If the types are not compatible, I want to instantiate a new instance of T2, assign it via the setter, and invoke copyData recursively on the object I get from the getter (as source) and the newly created instance (as destination). The assumption is here, that the occurring source and destination objects are incompatible but have matching getter and setter names and at the leaves of the object tree, the types of the getters and setters are compatible so that the recursion ends.
    The core of the problem I am struggling with is the step where I instantiate the new destination object. If T2 is a non-generic type, this is straightforward. However, imagine T1 and T2 are parametrized collections: T1 is List<T3> and T2 is List<T4>. Then I need special handling of the collection. I can easily iterate over the elements of the source List and get the types of the elements, but I can not instantiate only a generic version of the destinatino List. Further I cannot create elements of T4 and add it to the list of T2 and go into recursion, since the information that the inner type of the destination list is T4 is not available at run-time.
    public class Source {
       T1 getA();
       setA(T1 x);
    public class Dest {
       T2 getA();
       setA(T2 x);
    public class BeanDataCopier {
       public static void copyData(Object source, Object destination) {
          for (Method getterMethod : sourceGetterMethods) {
             ... // find matching getter and setter names
             Class sourceParamT = [class of return value of the getter];
             Class destParamT = [class of single param of the setter];
             // special handling for collections -  I could use some help here
             // if types are not compatible
             Object destParam = destination.getClass().newInstance();
             Object sourceParam = source.[invoke getter method];
             copyData(sourceParam, destParam);
    // usage of the method
    Souce s = new Source(); // this is an example, I do not know the type of s at copying time
    Dest d = new Dest(); // the same is true for d
    // initialize s in a complicated way (actually JAX-B does this)
    // copy values of s to d
    BeanDataCopier.copyData(s, d);
    // now d should have copied values from s Can you provide me with any alternative approaches to implement this "duck typing" behaviour on copying properties?
    Best regards,
    Patrik
    PS: You might have guessed my overall use case: I am sending an object tree over a web service. On the server side, the web service operation has a deeply nested object structure as the return type. On the client side, these resulting object tree has instances not of the original classes, but of client classes generated by axis. The original and generated classes are of different types but have the identically named getter and setter methods (which again have incompatible parameter types that however have consistent names). On the client side, I want to simply create an object of the original class and have the values of the client object (including the whole object tree) copied into it.
    Edited by: Patrik_Spiess on Sep 3, 2008 5:09 AM

    As I understand your use case this is already supported by Axis with beanMapping [http://ws.apache.org/axis/java/user-guide.html#EncodingYourBeansTheBeanSerializer]
    - Roy

  • 'ResourceDictionary' root element is a generic type and requires a x:Class attribute to support the x:TypeArguments attribute sp

    Error : 'ResourceDictionary' root element is a generic type and requires a x:Class attribute to support the x:TypeArguments attribute specified on the root element tag.
    Hi,
    I get this error when i include some namespaces in my ResourceDictionary to specify a Style for a custom control.
    Can anyone help me?
    Thx
    Stardusty

    Hi,
    That's the whole point. I don't want to use x:TypeArguments on a ResourceDictionary but the compiler says it needs it.
    And i don't know why.
    This code give no error:
    <ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespaceystem;assembly=mscorlib">  
    </ResourceDictionary>
    And by adding 3 namespaces it gives that weard error:
    <ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:MyTime.View.Controls"
    xmlns:converters="clr-namespace:MyTime.View.Converters"
    xmlns:validationrules="clr-namespace:MyTime.View.ValidationRules"
    xmlns:sys="clr-namespaceystem;assembly=mscorlib">  
    </ResourceDictionary>

  • Generic classes with parameterized super class and interface

    Hello.
    I'm trying to write a generic class that looks like the following pseudo-code.
    public interface Interface {
        public Interface getSibling(...);
    public class Klass {...}
    public class MyKlass<T extends Klass, T2 extends Interface>
            extends T implements T2 {
        public T2 getSibling(...) {
            return this;
    }where Interface and Klass each have various extensions.
    I came across this problem, or challenge, while writing classes for testing my EJBs. I tried and failed various attempts.
    Is it possible to write generic classes of this nature in Java?
    If so, please tell me and others who are like me.
    Thanks in advance.

    No. That would not work.
    Beside being forbidden by the compiler, to my understanding, it cannot be done in theory either, as the parameterized types get bound at instantiation time and are not available for static reference, which both extends and implements require.

  • Generics w/ abstract classes and contructors

    Here's my setup:
    abstract class AC
    AC(){};
    AC(String S){};
    abstract boolean IsValid();
    class RC extends AC
    public RC(){.........................};
    public RC(String S){...........................};
    public boolean IsValid(){...........................};
    class ACContainer<T extends AC>
    public void ErrorFunc(String Str)
    T tobj = new T(Str);
    My problem is that it doesn't let ErrorFunc create a "new T(Str)" when I create an ACContainer<RC> RCContObj with a call to ErrorFunc.
    Why not?
    I get "unexpected type"
    Edited by: mikeatrxs on Apr 24, 2008 1:10 PM
    Edited by: mikeatrxs on Apr 24, 2008 1:11 PM

    Reac a Generics tutorial. Type parameters are erased at compile time. There is no way it knows at runtime what class you want to create an instance of, unless you additionally pass in a Class object that tells it what class it is. It makes more sense if you ask, what happens when you "erase" the generic type parameters? Any valid Generics program should be able to erase to a valid non-Generics program and vice versa. But how are you going to erase the "new T(Str)"? How would you do this without Generics?

  • EclipseLink + JPA + Generic Entity + SINGLE_TABLE Inheritance

    I was wondering if it's possible in JPA to define a generic entity like in my case PropertyBase<T> and derive concrete entity classes like ShortProperty and StringProperty and use them with the SINGLE_TABLE inheritance mode? If I try to commit newly created ElementModel instances (see ElementModelTest) over the EntityManager I always get an NumberFormatException that "value" can't be properly converted to a Short. Strangely enough if I define all classes below as inner static classes of my test case class "ElementModelTest" this seems to work. Any ideas what I need to change to make this work?
    I'm using EclipseLink eclipselink-2.6.0.v20131019-ef98e5d.
    public abstract class PersistableObject
        implements Serializable {
        private static final long serialVersionUID = 1L;
        private String id = UUID.randomUUID().toString();
        private Long version;
        public PersistableObject() {
               this(serialVersionUID);
        public PersistableObject(final Long paramVersion) {
              version = paramVersion;
        public String getId() {
    return id;
        public void setId(final String paramId) {
      id = paramId;
        public Long getVersion() {
    return version;
        public void setVersion(final Long paramVersion) {
      version = paramVersion;
        public String toString() {
      return this.getClass().getName() + "[id=" + id + "]";
    public abstract class PropertyBase<T> extends PersistableObject {
        private static final long serialVersionUID = 1L;
        private String name;
        private T value;
        public PropertyBase() {
    this(serialVersionUID);
        public PropertyBase(final Long paramVersion) {
      this(paramVersion, null);
        public PropertyBase(final Long paramVersion, final String paramName) {
      this(paramVersion, paramName, null);
        public PropertyBase(final Long paramVersion, final String paramName, final T paramValue) {
      super(paramVersion);
      name = paramName;
      value = paramValue;
        public String getName() {
    return name;
        public void setName(final String paramName) {
      name = paramName;
        public T getValue() {
    return value;
        public void setValue(final T paramValue) {
      value = paramValue;
    public class ShortProperty extends PropertyBase<Short> {
        private static final long serialVersionUID = 1L;
        public ShortProperty() {
    this(null, null);
        public ShortProperty(final String paramName) {
      this(paramName, null);
        public ShortProperty(final String paramName, final Short paramValue) {
      super(serialVersionUID, paramName, paramValue);
    public class StringProperty extends PropertyBase<String> {
        private static final long serialVersionUID = 1L;
        protected StringProperty() {
    this(null, null);
        public StringProperty(final String paramName) {
      this(paramName, null);
        public StringProperty(final String paramName, final String paramValue) {
      super(serialVersionUID, paramName, paramValue);
    public class ElementModel extends PersistableObject {
        private static final long serialVersionUID = 1L;
        private StringProperty name = new StringProperty("name");
        private ShortProperty number = new ShortProperty("number");
        public ElementModel() {
    this(serialVersionUID);
        public ElementModel(final Long paramVersion) {
      super(paramVersion);
        public String getName() {
      return name.getValue();
        public void setName(final String paramName) {
      name.setValue(paramName);
        public Short getNumber() {
      return number.getValue();
        public void setNumber(final Short paramNumber) {
      number.setValue(paramNumber);
    <?xml version="1.0" encoding="UTF-8" ?>
    <entity-mappings version="2.1"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd">
    <mapped-superclass
      class="PersistableObject">
      <attributes>
      <id name="id">
      <column name="id" />
      </id>
      <version name="version" access="PROPERTY">
      <column name="version" />
      </version>
      </attributes>
    </mapped-superclass>
    <entity class="PropertyBase">
      <table name="PropertyBase" />
      <inheritance />
      <discriminator-column name="type"/>
      <attributes>
      <basic name="name">
      <column name="name" />
      </basic>
      <basic name="value">
      <column name="value" />
      </basic>
      </attributes>
    </entity>
    <entity class="StringProperty">
      <discriminator-value>StringProperty</discriminator-value>
    </entity>
    <entity class="ShortProperty">
      <discriminator-value>ShortProperty</discriminator-value>
    </entity>
    <entity class="ElementModel">
      <table name="ElementModel" />
      <inheritance />
      <discriminator-column name="type"/>
      <attributes>
      <one-to-one name="name">
      <join-column name="name" referenced-column-name="id" />
      <cascade>
      <cascade-all />
      </cascade>
      </one-to-one>
      <one-to-one name="number">
      <join-column name="number" referenced-column-name="id" />
      <cascade>
      <cascade-all />
      </cascade>
      </one-to-one>
      </attributes>
    </entity>
    </entity-mappings>
    public class ElementModelTest extends ModelTest<ElementModel> {
        public ElementModelTest() {
      super(ElementModel.class);
        @Test
        @SuppressWarnings("unchecked")
        public void testSQLPersistence() {
      final String PERSISTENCE_UNIT_NAME = getClass().getPackage().getName();
      new File("res/db/test/" + PERSISTENCE_UNIT_NAME + ".sqlite").delete();
      EntityManagerFactory factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
      EntityManager em = factory.createEntityManager();
      Query q = em.createQuery("select m from ElementModel m");
      List<ElementModel> modelList = q.getResultList();
      int originalSize = modelList.size();
      for (ElementModel model : modelList) {
          System.out.println("name: " + model.getName());
      System.out.println("size before insert: " + modelList.size());
      em.getTransaction().begin();
      for (int i = 0; i < 10; ++i) {
          ElementModel device = new ElementModel();
          device.setName("ElementModel: " + i);
        device.setNumber((short) i);
          em.persist(device);
      em.getTransaction().commit();
      modelList = q.getResultList();
      System.out.println("size after insert: " + modelList.size());
      assertTrue(modelList.size() == (originalSize + 10));
      em.close();

    This was answered in a cross post here java - EclipseLink + JPA + Generic Entity + SINGLE_TABLE Inheritance - Stack Overflow
    Short answer: No, it shouldn't work as the underlying database field type would be constant.  So either the Short or the String would have problems converting to the database type if they both mapped to the same table field. 

  • Class override, how to create the child class and then the base class

    I started to write a program for a smart DMM, the problem is every version of the DMM the company change the communication commend.
    My idea is to write a child class for every DMM version and every SubVI of the child will override the base class SubVI.
    My problem is, i want first to create one child class and after i will see every thing is work,  start to create the base class. that way i will see if am thinking the right way.
    My question is
    How can i create a child class and then create the base class and configure the SubVi of the child class to be Override of the base class?
    I tried to search in the property of the class but i didn't see nothing.
    Thanks
    Solved!
    Go to Solution.

    This can be done and I've done it on occasion.
    You simply create the base class with the dynamic dispatch methods you require (connector panes need to be identical to thos of the child class).
    Then set the inheritance of the class to inherit from this base class.  If your method is defined as a dynamic dispatch method in the parent, you'll most likely now have some errors (unless your child method was already DD in which case you might just be OK already).
    To change the inheritance of a class, right-click the properties of the class in your project and select properties.  I believe the ineritance tree is at the lower end of the properties.  Click on the "change inheritance" (or something similar) to choose the class from which you now wish to inherit.
    Say hello to my little friend.
    RFC 2323 FHE-Compliant

  • I don't know what's wrong with my code. it's about class and object.

    * This is generic type of Person
    package myManagement;
    * @author roadorange
    public class Person {
    private String SS;
    private String firstName;
    private String lastName;
    private String middleName;
    private String phoneNumber;
    private String address;
    private String birthDay;
    public void setSS (String SS) {
    this.SS = SS;
    public String getSS() {
    return SS;
    public void setFirstName (String firstName) {
    this.firstName = firstName;
    public String getFirstName() {
    return firstName;
    public void setLastName (String lastName) {
    this.lastName = lastName;
    public String getLastName() {
    return firstName;
    public void setMiddleName (String middleName) {
    this.middleName = middleName;
    public String getMiddleName() {
    return middleName;
    public void setPhoneNumber (String phoneNumber) {
    this.phoneNumber = phoneNumber;
    public String getPhoneNumber() {
    return phoneNumber;
    public void setAddress (String address) {
    this.address = address;
    public String getAddress() {
    return address;
    public void setBirthDay (String birthDay) {
    this.birthDay = birthDay;
    public String getBirthDay() {
    return birthDay;
    public void Person() {
    SS = "1234567890";
    this.firstName = "abc"; //test the keyword "this"
    this.lastName = "xyz";
    middleName = "na";
    phoneNumber = "123456789";
    address = "11-11 22st dreamcity ny 11111";
    birthDay = "11-11-1980";
    public void print() {
    System.out.println("Display Database\n"
    + "Social Security Number: *********" + "\n"
    + "First Name: " + getFirstName() + "\n"
    + "Middle Name: " + getMiddleName() + "\n"
    + "Last Name: " + getLastName() + "\n"
    + "Phone Number: " + getPhoneNumber() + "\n"
    + "Address: " + getAddress() + "\n"
    + "getBirthDay: " + getBirthDay() );
    package myManagement;
    //this class is used to test other class or test other object
    public class testClass extends Person{
    public static void main(String[] args) {
    Person obj1 = new Person();
    obj1.print();
    System.out.println(obj1.getFirstName()); //test the object
    Result:
    Display Database
    Social Security Number: *********
    First Name: null
    Middle Name: null
    Last Name: null
    Phone Number: null
    Address: null
    getBirthDay: null
    null
    i don't know why it's all null. i assign something in the default constructor. it shouldn't be "null".
    does anyone know why?

    when you create 2 class using netbean editor, person.java and test.java
    i never compile person.java.
    when i finish typing these 2 class and i just right click test.java and run.
    my question is do i need to compile person.java before i run test.java directly??
    does Netbean compile it automatically when i run test.java first time?
    i add another constructor Person constuctor with one parameter in Person.java and create 2nd object to test the 2nd constuctor and run.
    All the codes work, so does the first default constructor. i don't why is that.
    Then i removed what i added and restore back to where it didn't work before and test again. it works.
    @_@. so weird.
    problem solved. thank you
    Edited by: roadorange on Feb 25, 2008 7:43 PM

Maybe you are looking for