List in Wrapper Class
1 (a) .Create a Wrapper class student with data members (name, age and phone)
1 (b). Create List of student wrapper class and add three student objects to the list
public class Student{ public string name ; public String phone; public Integer age; }
Test the below in Developer Console
List<Student> students = new List<Student>(); Student s1 = new Student(); s1.Name = 'Kiran'; s1.phone = '123'; s1.age = 20; Student s2 = new Student(); s2.name = 'hari'; s2.phone = '456'; s2.age=90; students.add(s1); students.add(s2);
2 (a) Create a wrapper class Employee with data members and constructor to accept empName and salary
i. empName
ii. salary
iii. doj
iv. employee(empName, salary)
public class Employee{ public String empName; public Decimal salary; public Date doj; public Employee(String empName,Decimal salary){ this.empName= empName; this.salary = salary; doj = System.today(); } }
2 (b) Create List of employee class and insert three employee records to the list
List<Employee> employees = new List<Employee>(); Employee e1 = new Employee('sam', 30000); employess.add(e1); Employee e2 = new Employee('navya', 50000); employess.add(e2); Employee e3 = new Employee('Pravin', 40000); employess.add(e3);