in Education by
what can I do to use the getTotalScore method on the Program class to get the total of my scores ArrayList, and why must I do that? I wanna understand. Please note I don't wanna make the method static. import java.util.*; public class Program { public int getTotalScore(ArrayList v) { return total; } public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList scores = new ArrayList<>(); } } I can't find an article to help me understand clearly what is up, please help. I got this comment somewhere: Note that the scores object is not static, so you will have to make an instance of the Program class in order to use the scores ArrayList and the getTotalScore method. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
If you want to use a non-static member of a class, you must instantiate the class. So in this case new Program().getTotalScore(scores) This is very weird, to create an instance of the Program class. Move the method getTotalScore to a new class instead (or make it static). For calculating the total, look up how to “sum” an array of integers.

Related questions

0 votes
    Can abstract keyword be used with constructor, Initialization Block, Instance Initialization and Static Initialization ... Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    What are the uses of the keyword static?...
asked Jan 23, 2021 in Technology by JackTerrance
0 votes
    can someone please explain me “this” keyword in java in brief and its use Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    What is the use of ‘this’ keyword in java Answer in simple words Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    What is the use of ‘this’ keyword in java Answer in simple words Select the correct answer from above options...
asked Dec 18, 2021 in Education by JackTerrance
0 votes
    What is not the use of this keyword in Java? (a) Passing itself to another method (b) Calling ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    2 differences between static and nonstatic data members in Java Select the correct answer from above options...
asked Dec 16, 2021 in Education by JackTerrance
0 votes
    I am trying to understand Static methods in java. I have done a basic python before, so I am ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I am trying to understand Static methods in java. I have done a basic python before, so I am ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 13, 2022 in Education by JackTerrance
0 votes
    I am building a small website for fun/learning using a fairly standard Web/Service/Data Access layered ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    I am building a small website for fun/learning using a fairly standard Web/Service/Data Access layered ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    I am building a small website for fun/learning using a fairly standard Web/Service/Data Access layered ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    I am building a small website for fun/learning using a fairly standard Web/Service/Data Access layered ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    As it currently stands, this question is not a good fit for our Q&A format. We expect answers to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
...