Program to define a class 'employee' with data members as empid, name and salary. Accept data for 5 objects using Array of objects and print it.
This program demonstrates you the array of objects. Array of object is the collection of objects of the same class. The given syntax will define an array of reference therefore assign object to individual reference in the array to declare the array of object. The syntax to define array of object is:
<class-name> <array-name> [size];
For example, the following statement will define an array of object having size 6 references to the class Box.
Box b[6];
For creating an array of objects (allocating memory) you have to write down the following statements
for (int i=0; i<6; i++) {
b[i] = new Box();
// Assigning object to individual reference in the array.
}
PROGRAM
import java.util.Scanner;
public class Employee {
int empid;
String name;
float salary;
public void getInput() {
Scanner in = new Scanner(System.in);
System.out.print("Enter the empid :: ");
empid = in.nextInt();
System.out.print("Enter the name :: ");
name = in.next();
System.out.print("Enter the salary :: ");
salary = in.nextFloat();
}
public void display() {
System.out.println("Employee id = " + empid);
System.out.println("Employee name = " + name);
System.out.println("Employee salary = " + salary);
}
public static void main(String[] args) {
Employee e[] = new Employee[5];
for(int i=0; i<5; i++) {
e[i] = new Employee();
e[i].getInput();
}
System.out.println("**** Data Entered as below ****");
for(int i=0; i<5; i++) {
e[i].display();
}
}
}
OUTPUT
C:\>javac Employee.java C:\>java Employee Enter the empid :: 101 Enter the name :: Smith Enter the salary :: 30250.0 Enter the empid :: 103 Enter the name :: Harsh Enter the salary :: 23560.0 Enter the empid :: 105 Enter the name :: Subhash Enter the salary :: 19823.0 Enter the empid :: 203 Enter the name :: Rohan Enter the salary :: 25230.0 Enter the empid :: 201 Enter the name :: Girish Enter the salary :: 32000.0 **** Data Entered as below **** Employee id = 101 Employee name = Smith Employee salary = 30250.0 Employee id = 103 Employee name = Harsh Employee salary = 23560.0 Employee id = 105 Employee name = Subhash Employee salary = 19823.0 Employee id = 203 Employee name = Rohan Employee salary = 25230.0 Employee id = 201 Employee name = Girish Employee salary = 32000.0
The above program is easy to understand and it makes me much comfort to study soon
ReplyDeleteIt's right
DeleteGreat Article android based projects
DeleteJava Training in Chennai
Project Center in Chennai
Java Training in Chennai
projects for cse
The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training
Sir,I want in io package
ReplyDeletePicture change or content shading change on mouseover, making mouse trails are on the whole conceivable through Javascript. let's code the right way
ReplyDeleteI want this program based on id number we have to print all the details of employee sir
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteGiving lapel pins or corporate logo adornments where the employees as of now have them would not make a significant part of the sensation or inspiration.Target view my schedule
ReplyDeleteI am hoping the same best effort from you in the future as well. In fact your creative writing skills has inspired me. artists contracts
ReplyDeletebut this program is not compiling in eclipse compiler and also some of the online compilers
ReplyDeleteThe best way to learn is to learn by doing. Go for a full program that does a task you wanted to do on a computer in the past, work on it, and when you are finished you will have learned a lot and you will have a useful (or at least entertaining) program which is far better than some toy program demonstrating lists.best laptop for programming
ReplyDeleteSuperb way of explaining, and great webdesign agencies blog to get wonderful information.
ReplyDeleteReally impressive post. I read it whole and going to share it with my social circules. I enjoyed your article and planning to rewrite it on my own blog. 法拉盛补习
ReplyDeleteAnother tip is to hold up a week or so until after another variant is discharged before applying the move up to your site. error establishing a database connection
ReplyDeletePersonally, I have found that to remain probably the most fascinating topics when it draws a parallel to. You may find two to three new levels inside L . a . Weight loss and any one someone is incredibly important. Initial stage may be real melting away rrn the body. lose weight data entry bookkeeper
ReplyDeleteIn the event that you know a programming language, at that point there is frequently a reasonable possibility that you can compose a program to achieve that task yourself. excel vba training london
ReplyDeleteI have read all the comments and suggestions posted by the visitors for this article are very fine,We will wait for your next article so only.Thanks! for more info
ReplyDeleteVery informative post! There is a lot of information here that can help any business get started with a successful social networking campaign. recruitment software
ReplyDeleteThis is an excellent post I seen thanks to share it. It is really what I wanted to see hope in future you will continue for sharing such a excellent post. inventory data entry
ReplyDeleteThanks for a wonderful share. Your article has proved your hard work and experience you have got in this field. Brilliant .i love it reading. satta king
ReplyDeleteIt is regularly contrasted with speculative chemistry. Everybody recognizes what SEO specialists do, yet not many skill they do it. SEO lead generation
ReplyDeleteYour post is a very excellent . smoothie king store number
ReplyDeleteIt’s a nice blog with very useful information!!!
ReplyDeleteJAVA Training in Chennai
Selenium Training in Chennai
Python Training in Chennai
AWS Training in Chennai
Data Science Course in Chennai
DevOps Training in Chennai
More impressive Blog!!! Thanks for sharing this wonderful blog with us.
ReplyDeleteDigital Marketing Course in Chennai
Online Digital Marketing Course
Digital Marketing Course in Coimbatore
Finally I’m glad to check this blog because it’s a nice and informative blog.
ReplyDeleteSelenium Training in Chennai
Selenium Course in Bangalore
Selenium Training Online
Thanks for sharing this blog along with reference links.
ReplyDeleteData Science Training in Chennai
Hacking Course in Chennai
Such a useful blog with required information. Thanks for sharing this amazing blog.
ReplyDeleteAWS Certification in Chennai
DevOps Course in Chennai
I read this blog,Thanks for sharing this information.
ReplyDeleteJava Classes in Chennai
Nice Blog, it is very Impressive.keep sharing good information with us.
ReplyDeleteLearn Python Online
Python course in Chennai
Python Course in Bangalore
ReplyDeleteNice Blog, it is very Impressive.keep sharing good information with us.
Android Online Course
Android Course in Chennai
Android Course in Bangalore