0

How to call print() method of class Question by creating a method named studentMethod().

// This is the main class Question public class Question{ public static void main(String[] args) { // Object of the main class is created Question q = new Question(); // Print method on object of Question class is called q.studentMethod(); } // 'print()' method is defined in class Question void print(Question object){ System.out.print("Well Done!"); } // Define a method named 'studentMethod()' in class Question // Call the method named 'print()' in class Question } /*also I don't understand the argument passed in print(Question object). what does it mean?? */

22nd Aug 2019, 8:30 AM
Navneet
Navneet - avatar
6 Antworten
+ 4
They are called methods in java because there inside a class, //just create the method inside Question class and call the print method like so, public void studentMethod(){ print(argument is needed here); } //because print is a void method nothing is returned and just executes the body of that method
22nd Aug 2019, 10:47 AM
D_Stark
D_Stark - avatar
+ 2
I can only see that when you create a object of Question class theres a method called print that accepts an instance of the Question object but does nothing with it and just prints "well done" there is no student method so q.studentMethod wont work.
22nd Aug 2019, 9:14 AM
D_Stark
D_Stark - avatar
+ 2
If you have doubts just keep asking until you understand 👍
22nd Aug 2019, 10:52 AM
D_Stark
D_Stark - avatar
+ 1
thanks
22nd Aug 2019, 10:49 AM
Navneet
Navneet - avatar
0
thanks, and if we create a studentMethod(){ ... } what should we put between the method or function, so it calls the method print().
22nd Aug 2019, 9:24 AM
Navneet
Navneet - avatar
- 1
public void studentMethod() { Question q1 = new Question(); print(q1); }
5th Feb 2020, 10:17 AM
Dr E Ramadevi
Dr E Ramadevi - avatar