What's new

Java Help generic classes

_KaNeKi_

Eternal Poster
Joined
Jan 15, 2017
Posts
921
Solutions
1
Reaction
151
Points
438
Age
24
Patulong nga po dito sa exercise po. Salamat po.

Fix the FavoriteClasses class to use generics for it's three variables, favorite1, favorite2, and favorite3, it's constructor, and it's three functions to return each variable, as well as fixing r in the main section.
Then define a variable of the FavoriteClasses class and use "Hello", 67, 6.3 as the arguments for the constructor, and when you define it use your favorite classes/types that go with the three arguments.



import java.util.*;
public class Main{
public static class FavoriteClasses{
private favorite1;
private favorite2;
private favorite3;
FavoriteClasses(fav1, fav2, fav3){
this.favorite1=fav1;
this.favorite2=fav2;
this.favorite3=fav3;
}
public getFav1(){
return(this.favorite1);
}
public getFav2(){
return(this.favorite2);
}
public getFav3(){
return(this.favorite3);
}
}
public static main(String[] args){
List r=new ArrayList();
r.add(6.3);
r.add(5.9);
FavoriteClasses a=new FavoriteClasses("Hello",67,r.get(0));
System.out.println("My favorites are " + a.getFav1() + ", " a.getFav2() + ", and " + a.getFav3() + ".");
}
}



Eto po ung link.
You do not have permission to view the full content of this post. Log in or register now.


Salamat po
 

Similar threads

Back
Top