Computer Science, asked by th3darkstar, 7 months ago

Define a class ‘Equivalent’ described as below:

Instance Variables/Data Members

· int n - to store first number

· int m - to store second number

Member Methods

- Equivalent(int x,int y) : parameterised constructor to assign values to member variables

- int sumFactor(int num): to calculate and return sum of the factors of num

- void check(): to check whether the number is an Equivalent Number or not

[Equivalent numbers are numbers where the factors sum (other than the number itself) are identical. For example: 159 and 559 are equivalent numbers since their sum of their factors is same, i.e., 159 = 1, 3, 53 and 159, where 1 + 3 + 53 = 57.

Also, 559 = 1, 13, 43 and 559, where 1 + 13 + 43 = 57]

Write a main method to create an object of the class and call the above member methods.

Answers

Answered by awadhkishors162
1

Answer:

A method is a collection of statements that perform some specific task and return the result to the caller. A method can perform some specific task without returning anything. Methods allow us to reuse the code without retyping the code. In Java, every method must be part of some class which is different from languages like C, C++, and Python.

Methods are time savers and help us to reuse the code without retyping the code.

Method Declaration

In general, method declarations has six components :

Modifier-: Defines access type of the method i.e. from where it can be accessed in your application. In Java, there 4 type of the access specifiers.

public: accessible in all class in your application.

protected: accessible within the class in which it is defined and in its subclass(es)

private: accessible only within the class in which it is defined.

default (declared/defined without using any modifier) : accessible within same class and package within which its class is defined.

The return type : The data type of the value returned by the method or void if does not return a value.

Method Name : the rules for field names apply to method names as well, but the convention is a little different.

Parameter list : Comma separated list of the input parameters are defined, preceded with their data type, within the enclosed parenthesis. If there are no parameters, you must use empty parentheses ().

Exception list : The exceptions you expect by the method can throw, you can specify these exception(s).

Method body : it is enclosed between braces. The code you need to be executed to perform your intended operations

Explanation:

please add me in the brain list

Similar questions