Question: Find the error in each of the following program segments. Explain how to correct the error. a) void g() { System.out.println(Inside method g); void h()

Find the error in each of the following program segments. Explain how to correct the error. 

a)
    void g() {
    System.out.println("Inside method g");

    void h() {
    System.out.println("Inside method h");
    }
    }

b)
    int sum(int x, int y) {
    int result;
    result = x + y;
    }

c)
    void f(float a); {
    float a;
    System.out.println(a);
    }

d)
    void product() {
    int a = 6;
    int b = 5;
    int c = 4;
    int result = a * b * c;
    System.out.printf("Result is %d%n", result);
    return result;
    }

Step by Step Solution

3.46 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a Error The method returns a value when its not supposed to Correctio... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java How to Program Early Objects Questions!