Click here to Skip to main content
15,748,748 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to access and use 3 private variables in an Abstract Class( from another class that has extended ( from the previously mentioned Abstract Class.

From the sub class I want to access the getters() and setters() of the main class's.

In the main class (this is an abstract class) there is an abstract method called ShowInfo().

This ShowInfo() abstract method should do something to view the each instance of the subclass's.

Below is the source code for the MainClass(Abstract) and the Sub Class SubAbstract. Please refer them.

What I have tried:


package abstractionexample;
public abstract class MainAbstract {

    private String sName;
    private String sType;
    private int iQty;

     public String getsName() {
        return sName;

     public void setsName(String sName) {
         this.sName = sName;

     public String getsType() {
        return sType;

     public void setsType(String sType) {
        this.sType = sType;

      public int getiQty() {
         return iQty;

       public void setiQty(int iQty) {
           this.iQty = iQty;

        public abstract void showInfo();

        public static void main(String[] args) {       


package abstractionexample;

public class SubAbstract extends MainAbstract{

    public void showInfo() {


     //This is an instance and the getters() and setters() should use each    instance of this kind of to get values and set values.
     SubAbstract nSubAbs = new SubAbstract();  

Updated 12-Nov-16 21:07pm

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900