Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. public interface MainIfc {}
  2.  
  3. class Ifc1 implements MainIfc {
  4. private String a1;
  5. public String getA1() {
  6. return a1;
  7. }
  8. public void setA1(String a1) {
  9. this.a1 = a1;
  10. }
  11. }
  12.  
  13. class Ifc2 implements MainIfc {
  14. private String x1;
  15. private String x2;
  16. public String getX1() {
  17. return x1;
  18. }
  19. public void setX1(String x1) {
  20. this.x1 = x1;
  21. }
  22. public String getX2() {
  23. return x2;
  24. }
  25. public void setX2(String x2) {
  26. this.x2 = x2;
  27. }
  28. }
  29.  
  30. public class GetIfc {
  31. public Class getIfcType(int code) {
  32. if (code==1)
  33. return Ifc1.class;
  34. else
  35. return Ifc2.class;
  36. }
  37. public MainIfc getIfc(int code) {
  38. if (code==1) {
  39. Ifc1 thisIfc = new Ifc1();
  40. thisIfc.setA1("Ifc1");
  41. return thisIfc;
  42. } else {
  43. Ifc2 thisIfc = new Ifc2();
  44. thisIfc.setX1("Ifc2");
  45. thisIfc.setX2("Ifc2");
  46. return thisIfc;
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement