Sunday, August 6, 2023

Complete the code segment to call the method print() of class given class Printer to print the following.


 

Complete the code segment to call the method  print() of class given class Printer to print the following.


--------------------------------
Hi! I am class STUDENT
Hi! I class SCHOOL.
--------------------------------

Program :

// This is the class named Printer
class Printer { 
    // This are the methods in class Printer
    public void print() { 
System.out.println("Hi! I class SCHOOL."); 
    } 
    public void print(String s) { 
System.out.println(s); 
    } 

public class Question22{ 
    public static void main(String[] args) {
// Create an object of class Printer

Printer p = new Printer();

// Call 'print()' methods for desired output
p.print("Hi! I am class STUDENT");

p.print();
}
}


InputOutput
Test Case 1
Hi! I am class STUDENT
Hi! I class SCHOOL.

No comments:

Post a Comment