77 961
Assignments Done
Successfully Done
In August 2019

Answer to Question #65155 in Java | JSP | JSF for Annie

Question #65155
Change your fraction class so that its instance variables numerator and denominator are hidden (i.e. private). Check that your old client class will not now compile (i.e, if the Fraction class instance variable name ‘numerator’ was used in the client class).
Expert's answer
class Fraction{

private double numerator;
private double denominator;

public double getDecimalValue(){
return numerator/denominator;

public double getNumerator() {
return numerator;

public void setNumerator(double numerator) {
this.numerator = numerator;

public double getDenominator() {
return denominator;

public void setDenominator(double denominator) {
this.denominator = denominator;


class Demo {
public static void main(String[] args) {

Fraction test = new Fraction();

test.numerator = 1; //compilation error
test.denominator = 5; //compilation error

/* works clear*/



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions