Computer Science, asked by sambhavchaturvedi, 2 months ago

What are two types of methods that we can write in class?​

Answers

Answered by sh123prajapat
0

Answer:

Defining Methods

The next figure shows the code for Stack's push method. This method puts the object argument onto the top of the stack and returns the object.

The push Method and the Structure of a Method Definition

Like a class, a method definition has two major parts: the method declaration and the method body. The method declaration defines all the method's attributes, such as access level, return type, name, and arguments, as shown in the following figure. The method body is where all the action takes place. It contains the instructions that implement the method.

The only required elements of a method declaration are the method's name, return type, and a pair of parentheses: ( and ). A method declaration can provide more information about the method, including the return type of the method, the number and type of the arguments required by the method, and which other classes and objects can call the method. The next table shows all possible elements of a method declaration.

Similar questions