测试和子类

时间:2013-11-22 05:32:49

标签: java unit-testing testing

我想实现一个测试来检查我的子类。如何在运行时测试Customerextends Person类?

超级

   import java.util.Scanner;

         public class Person
         {
          private String name;
            private String address;
            private String number;

          public Person() //No Argument constructor//
          {
           name= "";
           address= "";
           number= "" ;
           }

           public Person(String num, String nam, String add) //Explicit value                  constructor//
            {
              number= num;
              name= nam;
              address= add;
            }
              public String getName() //Accessor method//
            {
              return name;
             }

              public void setName(String name )//Mutator method//
              {

               this.name= name;
                }

               public String getAddress()
                {
                 return address;
                }
               public void setAddress(String address)
                 {
                    this.address= address;
                  }
                public String getTelephoneNumber()
                   {
                    return number;
                        }
                 public void setNumber(String number)
                    {
                     this.number= number;
                      }

                    public String toString ()
                     {
                return name + "\n" + address + "\n" + number;
                   }}

子类

           public class Customer extends Person 
            {

           public Customer(String num, String nam, String add) 
             {
              super (num, nam, add);

               }

               public boolean checkResponse( char response)
              {
             if (response == 'Y'){return true;}
              return false;
                  }
              public void display()
                  {
               System.out.println(super.toString()); 
                   }
                     }

0 个答案:

没有答案