methods | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

methods

why cant we define the method name and definition inside the main function and use it and execute ...

9th Jul 2019, 9:46 AM
Aadhithya
Aadhithya - avatar
3 Answers
+ 2
We can't use method definaion in main. You should know the purpose of method is to reuse the method code anytime. According to the rules of syntax, we must define the method outside the main.
9th Jul 2019, 9:53 AM
Muhammad Rashid
Muhammad Rashid - avatar
+ 1
in c++, method has an another name called member function. it has to be defined inside of class and it can be reused by the instances of that class. otherwise it's going to throw a syntax error.
9th Jul 2019, 1:15 PM
Payton Zhong
Payton Zhong - avatar
+ 1
Java does not support nested methods. However, there are indirect ways to write a method in a method: https://www.google.de/amp/s/www.geeksforgeeks.org/method-within-method-in-java/amp/
9th Jul 2019, 1:40 PM
Denise Roßberg
Denise Roßberg - avatar