🔒 Closed Help generic classes

Status
Not open for further replies.

_KaNeKi_

Eternal Poster
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
 
Status
Not open for further replies.

About this Thread

  • 0
    Replies
  • 422
    Views
  • 1
    Participants
Last reply from:
_KaNeKi_

Online now

Members online
1,064
Guests online
713
Total visitors
1,777

Forum statistics

Threads
2,276,976
Posts
28,973,524
Members
1,229,678
Latest member
wow98
Back
Top