PRASHNIKAप्रश्निका
‹ Back to the paper

Given the following code snippet: package mine; public class Greetings { public static void…

Computer Science20252 marksShort answer
Given the following code snippet:
package mine; 
public class Greetings 
{ 
    public static void greet(String name) 
    { 
        System.out.println("Hello " + name + ", welcome to the world of programming"); 
    } 
} 

import java.util.*; 
import mine.*; 
public class Trial 
{ 
    public static void main() 
    { 
        Scanner sc = new Scanner(System.in); 
        System.out.println("Give your name"); 
        String n = sc.next(); 
        Greetings.greet(n); 
    } 
}
(a)[1.0]
Predict the output for n = “Abhay”;
(b)[1.0]
Explain the difference between the two statements: `import java.util.*;` and `import mine.*;`

Answer

Answer (a)

AI
Output: Give your name Hello Abhay, welcome to the world of programming

Answer (b)

AI
import java.util.*; imports all the classes of the built-in java.util package (e.g. Scanner, StringTokenizer). import mine.*; imports all the classes of the user-defined package mine (here, the class Greetings) that the programmer created.
Programming in Java (Review of Class XI Sections B and C)

From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 51.