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
5 odpowiedzi
+ 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();
}
}
}
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??
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);
}
}
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);
}
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);
}
}