java - ArrayList generics -
could me explain ma.add(new highrights("aaa")); does?
main class:
public static void main(string [] a){ arraylist<securityrights> ma=new arraylist<securityrights>(); ma.add(new highrights("aaa")); } highrights class:
public class highrights extends securityrights { private string name; public highrights(string n){ super(true); this.name = n; } public string getname(){ return name; } public static void main(string[] a){ highrights s= new highrights("lisa"); system.out.print(s.getname() +" "+s.getsecret()); } }
this simple inheritance example.
ma.add(new highrights("aaa")); it adds new object of highrights class list<securityrights> array list ma.
highrights extends securityrights this inheritance. possible store child object highrights parent object securityrights.
please read inheritance
Comments
Post a Comment