Guest User

Untitled

a guest
Jul 16th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. package com.art.fundamentals;
  2.  
  3. public class CompositionDemo {
  4.  
  5. public static void main(String[] args) {
  6. Question firstQuestion = new Question("Who won 2018 World Cup ?", "France", "Croatia");
  7. Question secondQuestion = new Question("Who hosted 2018 World Cup ?", "Russia", "USA");
  8.  
  9. System.out.println(firstQuestion);
  10. System.out.println(secondQuestion);
  11. }
  12.  
  13. }
  14.  
  15. class Question {
  16. private String question;
  17. private Option optionOne;
  18. private Option optionTwo;
  19.  
  20. Question(String question, String option1, String option2) {
  21. this.question = question;
  22. this.optionOne = new Option(1, option1);
  23. this.optionTwo = new Option(2, option2);
  24. }
  25.  
  26. @Override
  27. public String toString() {
  28. return "Question{" +
  29. "question='" + question + '\'' +
  30. ", optionOne=" + optionOne +
  31. ", optionTwo=" + optionTwo +
  32. '}';
  33. }
  34. }
  35.  
  36. class Option{
  37. int id;
  38. String name;
  39.  
  40. Option(int id, String name) {
  41. this.id = id;
  42. this.name = name;
  43. }
  44.  
  45. @Override
  46. public String toString() {
  47. return "Option{" +
  48. "id=" + id +
  49. ", name='" + name + '\'' +
  50. '}';
  51. }
  52. }
Add Comment
Please, Sign In to add comment