Demonstrate the concept of classes and objects in detail with any real time example.
Example 1: using class in java
class Number {
int number;
public boolean isSquare(){
double squareRoot = Math.sqrt(number);
if(squareRoot == Math.floor(squareRoot))
{
return true;
} else {
return false;
}
}
public boolean isTriangular(){
int x = 1;
int triangularNumber = 1;
while(triangularNumber < number){
x++;
triangularNumber = triangularNumber + x;
}
if(triangularNumber == number){
return true;
} else {
return false;
}
}
}
Number myNumber = new Number();
myNumber.number = 16;
System.out.println(myNumber.isSquare());
Example 2: class and object in oop
GREDSTEDTRDTDY