Complete the code segment to call print() method of class Question by creating a method named 'studentMethod()'. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Complete the code segment to call print() method of class Question by creating a method named 'studentMethod()'.

Where am I doing mistake in this code?? Please tell. Output should be : Well done https://code.sololearn.com/coJDye7516yC/?ref=app

29th Sep 2020, 6:33 PM
Atul Gautam
Atul Gautam - avatar
5 Answers
+ 2
Solution // This is the main class Question public class Question23{ public static void main(String[] args) { // Object of the main class is created Question23 q = new Question23(); Question23.Question a = q.new Question(); // Print method on object of Question class is called a.studentMethod(q); } // 'print()' method is defined in class Question void print(){ System.out.print("Well Done!"); } // Define a method named 'studentMethod()' in class Question // Call the method named 'print()' in class Question class Question{ public void studentMethod(Question23 a){ a.print(); } } }
29th Sep 2020, 6:56 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
0
Sumit Programmer😎😎 Thanks for help. But we can not edit anything above the comments "Call the method named 'print()' in class question". Is there any way to do the question following the above rule??
29th Sep 2020, 7:09 PM
Atul Gautam
Atul Gautam - avatar
0
// This is the main class Question public class Question23{ public static void main(String[] args) { Question q = new Question(); q.studentMethod(new Question23()); } void print(Question23 object){ System.out.print("Well Done!"); }} class Question{ void studentMethod(Question23 p){ p.print(p); } }
29th Sep 2020, 7:33 PM
Jayakrishna 🇮🇳
0
Problem: function contact(name, number) { this.name = name; this.number = number; } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); //Here is my code function contact(name, number){ console.log(name+ ": "+number); }
22nd Jun 2022, 10:38 PM
Natalie Sequita Wilder
Natalie Sequita Wilder - avatar
0
// This is the main class Question public class Question23{ public static void main(String[] args) { // Object of the main class is created Question23 q = new Question23(); // Print method on object of Question class is called q.studentMethod(); } // 'print()' method is defined in class Question void print(Question23 object){ System.out.print("Well Done!"); } // Define a method named 'studentMethod()' in class Question // Call the method named 'print()' in class Question void studentMethod(){ print(this); } }
9th Feb 2023, 6:32 PM
Vipul Kumar
Vipul Kumar - avatar