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?? */

8/22/2019 8:30:46 AM


5 Answers

New Answer


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


If you have doubts just keep asking until you understand 👍


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.




thanks, and if we create a studentMethod(){ ... } what should we put between the method or function, so it calls the method print().