Create a multi-file program where in one file a string message is taken as input from the user and the function to display the message on the screen is given in another file (make use of Scanner package in this program)
Create a multi-file program where in one file a string message is taken as input from the user and the function to display the message on the screen is given in another file (make use of Scanner package in this program).
Code of Package
- Make a Folder of any name eg. MultiFile
- Under that folder put code of package with any name eg. MultiFilepackage.java
package Multifile;
import java.util.Scanner;
public class MultifileProgram
{
public String str1;
public void read()
{
Scanner sc=new Scanner (System.in);
System.out.println("Enter String: ");
str1=sc.nextLine();
}
Code to import Package
- Import the code of package file you put in your folder
- In my case folder is MultiFile and name of code file is MultiFilepackage.java so import MultiFile.MultiFilepackage.java
import Multifile.MultifileProgram;
public class Multifile
{
public static void main(String[] args)
{
MultifileProgram p1=new MultifileProgram();
p1.read();
System.out.println("Out put after read multifile program: "+p1.str1);
}
}
Ouput:
Enter String:
Sarthak Mund S3
Out put after read multifile program: Sarthak Mund S3
Post a Comment