08/01/25 ---------- Q)What are the similarities between a structure in C and a class in Java? =>Both are user defined data types. =>Both are meant for designing a real world entity. For eg. a book, an employee, an account =>Both represent fields/attributes of a real world entity. For eg. struct Account{ int accno; float balance;//attributes of an Account ....... } class Account{ int accno; float balance; ....... } Q)What is the difference between a structure in C and a class in Java? structure class ****************************************************** 1)only real world entity's represents both data can be represented. But code can't be. 2)doesn't support supports encapsulation encapsulation. ************************************************** Q)What are the similarities between a structure variable in C and an object in Java? =>both represent a real world entity. For eg. one bank account, an employee =>Both are data storage areas in RAM to store application's data. Q)What are the differences between a structure variable in C and an object in Java? structure variable object **************************************** 1)only data storage holds data area. But no code is associated and code to process that with it. data is also associated with it. 2)It is not an encapsulated It is. unit. 3)application's data is not secure application data is secure if stored in it. if stored in it. Q)Write a Java program that stores 1 employee data(empno,name,salary) into computer memory and displays their details. DIAGRAM //EmployeeApplication.java class Employee{ int empno; String name; float salary;//instance variables void storeEmployeeData(){ empno=10001; name="Rama"; salary=50000; }//instance method void displayEmployeeData(){ System.out.println("EMPNO:"+empno); System.out.println("NAME:"+name); System.out.println("SALARY Rs."+salary); }//instance method }//Employee data type created class EmployeeApplication{ public static void main(String args[]){ Employee e1=new Employee(); e1.storeEmployeeData(); e1.displayEmployeeData(); } }