Access a private variable from the superclass (JAVA)

后端 未结 6 2075
终归单人心
终归单人心 2021-02-08 20:19

Ok so I have studied java all semester and thought I had a clear understanding about inheritance and super/sub classes. Today we were given as assignment for making a superclass

6条回答
  •  后悔当初
    2021-02-08 21:00

    package com.action.product;
    
    public class ProductAction{
      public static String strCategoryName;
    
      public String getStrCategoryName() {
        return strCategoryName;
      }
      public void setStrCategoryName(String strCategoryName) {
        this.strCategoryName = strCategoryName;
      }
    
    }
    
    -----------------------------------------------------------------------
    
    package com.DAO.product;
    
    public class ProductDAO extends ProductAction {
    
       @SuppressWarnings("static-access")
       public String addnewProductValidation(){
           System.out.println("======through_name======="+super.strCategoryName);
    
           System.out.println("======through_getters======="+super.getStrCategoryName());
    
       }
    }
    

    Can initialize variables as static. No need to create object

提交回复
热议问题