Number Class with Methods defined Inside it
Learn to implement a class with member methods defined inside it.
We'll cover the following
Challenge
Write a self-sufficient class called Number
that maintains an int
member variable. It should have the following methods inside it to perform various operations on the int
:
-
void setNumber ( int n )
stores the value ofn
in the class’ member variable -
int getNumber( )
returns the current value ofNumber
class member variable -
void printNumber( )
prints the value ofint
member variable -
bool isNegative( )
checks whether the value ofint
member variable is negative -
bool isDivisibleBy ( int n )
checks whether theint
member variable is divisible byn
-
int absoluteValue( )
returns the absolute value of member variable
Coding exercise
Your job is to define the methods inside the Number
class given below.
Get hands-on with 1400+ tech skills courses.