Write a program that declares a class named Person. It should have instance variables to record name, age and salary. Use new operator to create a Person object. Set and display its instance variables.

 Program - 

import java.util.*;

public class persondata

{

public static void main(String[]args)

{

person a = new person();

a.set();

System.out.println("your data is \n\n");

a.display();

}

class person

{

private String name;

private int age;

private int salary;

 

public void display()

{

System.out.println("your name is :"+name);

System.out.println("your age is :"+age);

System.out.println("your salary is "+salary);

}

public void set(){

Scanner sc = new Scanner(System.in);

System.out.println("enter your name");

name = sc.next();

System.out.println("enter your age");

age = sc.nextInt();

System.out.println("enter your salary");

salary = sc.nextInt();

}

}

outpiut - 

 


Comments

All time Best Post

IMAGE CRUD OPERATION USING EXPRESS MONGOOSE MULTER

connect websocket to binance api and store t he true value in the db

CRUD APP WITH SORT IN NODE EXPRESS AND MONGODB

express session login system using node express mongodb

how to delete image from the folder directly from a Request (MULTER)

calculate rsi

java program for 1 to 10 print using while loop

How to fetch last one minute volume of BTC in CCXT Nodejs.