DUET PG Score Card 2021
NHAI Recruitment 2021
Bihar Board 12th Dummy Admit Card 2022
RBI Assistant Notification 2021
Jee Advanced 2021 Result
NIACL Assistant Recruitment 2021
SBI PO Online Form 2021

Write a Java program with a class name Staff, contains the data members id (int), name (String) which are initialized with a parameterized constructor and the method show()

Write a Java program with a class name Staff, contains the data members id (int), name (String) which are initialized with a parameterized constructor and the method show().

The member function show() is used to display the given staff data.

Write the main() method with in the class which will receive two arguments as id and name.

Create an object to the class Staff with arguments id and name within the main(), and finally call the method show() to print the output.

If the input is given as command line arguments to the main() as “18”, “Gayatri” then the program should print the output as:

Id : 18
Name : Gayatri

Solution:

package q11116;

public class Staff{
	int id;
	String name;
	
	public void show(int id, String name){
		System.out.println("Id : "+id);
		System.out.println("Name : "+ name);
	}
	
	public static void main(String[] args){
		
		int id = Integer.parseInt(args[0]);
		Staff st1 = new Staff();
		
		st1.show(id,args[1]);
	}
}

Candidates having any kind of query so he/she can ask in our comment section. Our Panel will b reverting back as soon as possible. Thank You. For more details visit our website (https://speedjobalert.com/)

Leave a Comment