How to get the fields of Abstract class in sub class (CORE JAVA) -


this abstract class

i can't print fields inside abstract class display method in subclass

public abstract  class account {     private int cusid;     private int cusaccountid;     private string cusname;      account(int cusid, int cusaccountid,string cusname){         this.cusid=cusid;         this.cusname=cusname;         this.cusaccountid=cusaccountid;                  }       public int getcusid() {         return cusid;     }      public int getcusaccountid() {         return cusaccountid;     }      public string getcusname() {         return cusname;     }      abstract public void display();     } 

i extend abstract class(account) (savings class)

public class savings extends account{     private int savid;     private string  savbranch;       savings(int cusid, int cusaccountid,string cusname,int savid, string savbranch) {         super(cusid,cusaccountid,cusname);         this.savid= savid;         this.savbranch=savbranch;        }      @override     public void display() {         account s = null;         system.out.println(s.getcusid()+s.getcusaccountid()+s.getcusname()+savid+savbranch);             }                 } 

and here main

public class bank {      public static void main(string[] arg){          savings sc = new savings(2,2,"ram",4,"thambaram");         sc.display();     }  } 

and shows runtime error

exception in thread "main" java.lang.runtimeexception: uncompilable source code - erroneous tree type: <any>     @ com.trying.savings.display(savings.java:22)     @ com.trying.bank.main(bank.java:14) java result: 1 build successful (total time: 1 second) 

change display method savings class (you can access modifiers public):

@override public void display() {      system.out.println(this.getcusid()+" "+this.getcusaccountid()+" "+this.getcusname()+" "+savid+savbranch);  } 

you creating null account object , trying display fields not correct.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -