Given:
Which two methods facilitate valid ways to read instance fields? (Choose two.)
Given:
Which two methods facilitate valid ways to read instance fields? (Choose two.)
The methods getCCount and getTCount facilitate valid ways to read instance fields. The getCCount method returns the value derived from other instance fields and the getTotalCount method, facilitating access to the cCount. The getTCount method directly accesses the instance field tCount. Meanwhile, getACount returns the parameter passed to it rather than accessing the instance field, getGCount uses recursion leading to a StackOverflowError, and getTotalCount sums all instance fields instead of individually accessing one.
A and B are true
The correct answers is: A: return the value of c count, NOTE getTotalCount() is the sum of all fields (a+b+c +d), but getCount is retrive by aritmetic operation that getTotalCount() -a -b -g => then the value of c is B: return the value of tCount. NOT VALID: C-> retrieve the parameter value D-> throw a StackfOverflowExp.. E-> retrive thhe sum of all fields not a single value for some field
B & E are correct. code: int aCount; int tCount; int cCount; int gCount; int getAcount(int aCount) { return aCount; } int getTCount(int tCount){ return this.tCount; } int getGCount() { return getGCount(); } int getCCount() { return getTotalCount() - this.aCount - getTCount(0) - gCount; } int getTotalCount() { return aCount + getTCount(0) + this.cCount + this.gCount; }
getTotalCount cannot get a instance field, you get sum of all fields, but in getCcount you can get value of c count => getTotalCount() -a -b -g = ccount . E is not valid