java - Class in Android like Struct in Swift -


in app in swift have code:

struct question {     var questionlbl : string!     var answers : [string]!     var answer : int! } 

after use struct this

var questions = [question]()  questions =             [question(questionlbl: "whats name?", answers: ["john","josh","adam","leo"], answer: 0),                  question(questionlbl: "whats moms name?", answers: ["jessica","crystal","samanta","kate"], answer: 3),                  question(questionlbl: "whats fathers name?", answers: ["ed","blake","jeff","jonhson"], answer: 2)] 

now, i'm trying make same app android.. created class , tried same thing that.. class file:

public class question {     string questionlabel;     string[] answersoptions;     integer correctanswer;      public question(string questionlabel, string[] answersoptions, integer correctanswer) {         this.questionlabel = questionlabel;         this.answersoptions = answersoptions;         this.correctanswer = correctanswer;     }      public string getquestionlabel() {         return questionlabel;     }      public string[] getanswersoptions() {         return answersoptions;     }      public integer getcorrectanswer() {         return correctanswer;     } } 

and how try in main activity:

question[] questions;         questions = {                  question("whats name?",{"john","josh","adam","leo"}, 1),                  question("whats mom's name?",{"jessica","crystal","samanta","kate"}, 1)         }; 

but didn't work. whats problem?

look @ this post syntax of declaring arrays. essentially, it'd like:

questions = new question[]{     new question("what's name?", new string[]{"john","josh","adam","leo"}, 1),     new question("what's mom's name?", new string[]{"jessica","crystal","samanta","kate"}, 1)     //etc.. } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -