Using Constructors & Member Function to add two numbers: Java

In this Java video tutorial we have covered both ways of adding numbers: using constructors as well as using methods.

Constructors:

Constructor name and the class name must be same.
No return type.There are 3 types of constructors:1. Default constructors.2. Parameterized constructors.3. Copy Constructors.

In this video tutorials we have shown the use of Parameterized constructors.

calc(int a, int b)
{
no1 = a;
no2 = b;
}

calc(int a, int b)
{
no1 = a;
no2 = b;
}

Adding and displaying the result:

public void sum()
{
System.out.println("Sum of "+no1+" and "+no2+" is "+(no1+no2));
}

public void sum()
{
System.out.println("Sum of "+no1+" and "+no2+" is "+(no1+no2));
}

Strings are written inside double quotes and the variables written outside the double quotes will display the value stored in them.
+ (plus) is concatenation operation.
(no1+no2) adds the value present in no1 and no2 and displays the result of addition.