Answer to Question #152279 in Java | JSP | JSF for Hamza saeed

Question #152279
. Find the syntax errors in the definition of the following class:
public class BB
{
private int one;
private int two;
public boolean equal()
{
return (one == two);
}
public print()
{
System.out.println(one + " " + two);
}
public BB(int a, int b)
{
one = a;
two = b;
}
}
1
Expert's answer
2020-12-20T21:17:56-0500

The error is that the return value is not specified in the "Print" method signature. In this case, the method does not return anything, so in the method signature you need to write "void".

The correct code is below:


public class BB

{

    private int one;

    private int two;

    public boolean equal()

    {

        return (one == two);

    }

    public void print() // syntax error was HERE!

    {

        System.out.println(one + " " + two);

    }

    public BB(int a, int b)

    {

        one = a;

        two = b;

    }
    //driver to show how program works (just for example!!!) 
    public static void main(String[] args) {
        BB bb = new BB(1, 2);
        System.out.print("method \"print\": ");
        bb.print();
        System.out.println("\n method \"equal\": " + bb.equal());
    }

}


OUTPUT:


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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog