‹ Back to the paper
Given the following code snippet: package mine; public class Greetings { public static void…
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)
AIOutput:
Give your name
Hello Abhay, welcome to the world of programming
Answer (b)
AIimport 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.
From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 51.