0% found this document useful (0 votes)
3 views2 pages

Java Class for Algebraic Expression

This Java code defines an ExpressionExample class with integer instance variables a, b, z, y, and ans. It contains two constructors, one with no parameters and one that initializes a and b. The formulaAlgebra method calculates the value of ans using the formula (a*a)+(b*b)+(2*a*b) and prints the result. The main method creates two ExpressionExample objects, one initialized with a and b values of 2, and calls formulaAlgebra on the initialized object, outputting 20.

Uploaded by

riyazudheen
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Java Class for Algebraic Expression

This Java code defines an ExpressionExample class with integer instance variables a, b, z, y, and ans. It contains two constructors, one with no parameters and one that initializes a and b. The formulaAlgebra method calculates the value of ans using the formula (a*a)+(b*b)+(2*a*b) and prints the result. The main method creates two ExpressionExample objects, one initialized with a and b values of 2, and calls formulaAlgebra on the initialized object, outputting 20.

Uploaded by

riyazudheen
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ExpressionExample.

java

package ooconcepts;

public class ExpressionExample {

int a,z,y;

int b;

int ans;

public ExpressionExample(){

public ExpressionExample(int a,int b){

this.a = a;

this.b = b;

public void formulaAlgebra(){

ans = (a*a)+(b*b)+(2*a*b);

[Link]("Output is : " + ans);

public static void main(String[] args) {


ExpressionExample ee = new ExpressionExample(2,2);

ExpressionExample ii = new ExpressionExample();

[Link]();

You might also like