Created
July 16, 2018 22:38
-
-
Save arttuladhar/994403cd6d9636f276c2b0f5876989d1 to your computer and use it in GitHub Desktop.
Composition Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.art.fundamentals; | |
public class CompositionDemo { | |
public static void main(String[] args) { | |
Question firstQuestion = new Question("Who won 2018 World Cup ?", "France", "Croatia"); | |
Question secondQuestion = new Question("Who hosted 2018 World Cup ?", "Russia", "USA"); | |
System.out.println(firstQuestion); | |
System.out.println(secondQuestion); | |
} | |
} | |
class Question { | |
private String question; | |
private Option optionOne; | |
private Option optionTwo; | |
Question(String question, String option1, String option2) { | |
this.question = question; | |
this.optionOne = new Option(1, option1); | |
this.optionTwo = new Option(2, option2); | |
} | |
@Override | |
public String toString() { | |
return "Question{" + | |
"question='" + question + '\'' + | |
", optionOne=" + optionOne + | |
", optionTwo=" + optionTwo + | |
'}'; | |
} | |
} | |
class Option{ | |
int id; | |
String name; | |
Option(int id, String name) { | |
this.id = id; | |
this.name = name; | |
} | |
@Override | |
public String toString() { | |
return "Option{" + | |
"id=" + id + | |
", name='" + name + '\'' + | |
'}'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment