java - Cannot find symbol when creating an object in IO class using inheritance -
i'm trying create tourist object on io class , parameters specified correctly in respective class. however, wouldn't compile says cannot find symbol. because i'm using tourist sub-classes? compiler says cannot find symbol variable "nam" etc.. helping.
this method in io class..
private void addmembercard() { system.out.println("enter member name"); string name = reader.nextline(); system.out.println("select 1. tourist, 2. business"); system.out.println("enter choice"); int choice = reader.nextint(); membercard m; if (choice == 1){m = new tourist (nam, rat, cred, cit);} else if (choice == 2){m = new business(nam, rat);} preston.addmembercard(m); }
and constructor in tourist class
public tourist (string nam, int rat, int cred, string cit) { super(nam, rat, cred); city = cit; }
this has nothing inheritance. need understand difference between parameters , arguments. parameters nam
, rat
, cred
, , cit
exist within tourist
constructor. in addmembercard()
method, nam
, rat
, cred
, , cit
don't exist; markspace indirectly pointed out. need use arguments, existing variables actual value.
this should help: http://en.wikipedia.org/wiki/parameter_%28computer_programming%29#parameters_and_arguments
Comments
Post a Comment