Professional Documents
Culture Documents
public
public
public
public
String
String
String
String
collegeName;
city;
branch;
phone;
}
6.Create a class ProductData with data memebers
1.productName;
2.productCode
3.cost
4.quantity
public ProductData{
public
public
public
public
String productName;
String productCode;
Decimal cost;
Integer quantity;
}
7.create a class student with the following data members and methods
1. name
2. age
3. show() : void
This should display name and age value
public class Student{
public String name;
public Integer age;
public void show(){
System.debug('My Name :'+name);
System.debug('My Age :'+age);
}
}
-------------------------------------------------------------------------8 .Create a class Bank with follwing data members and methods
1.balance
2.deposit(amt) : void
This method wwill add the amt to the balance
3.withdraw( amt) : void
This method will reduce the amt from balance
4.display(): void
This method should display the balance
public class Bank{
public Decimal balance;
public void deposit(Decimal amt){
balance=balance+amt;
}
}
10.Create a class student with constructor
public class Student{
public Student(){
}
}
11. Create a class Employee with constructor
public class Employee{
public Employee(){
}
}
12.Create a class Student with a constructor where name is parameter
in the constructor
public class Student{
public Student(String name){
}
}
13.Create a class Employee with follwing data members and methods
1.
2.
3.
4.
name
exp
salary
Constructor() : Assign value to the data members in the
constructor
------------| name=null |
|
|
| age=null |
-------------Again i called new again it will allocate the memory
------------| name=null |
|
|
| age=null |
-------------Again if we call new it will allocate the memory again
------------| name=null |
|
|
| age=null |
-------------2. Once new keyword has assigned the memory then constructor is called
and it will intilize the data
--------------| name=satish |
|
|
| age=20
|
---------------3. Create a reference variable
This will store the refernce to the memeory location allocated by new
keyword
Primitive variables : Primitive variable contains data
Integer age ;
String name;
Decimal salary;
Boolean active;
Long a;
Blob body;
Refernce variables contain reference to memory locatiomn
Employee e;
Account a ;
Student std;
Object : object is a refernce variable or new Instance of the class
ClassName obj=new ClassName();
Student s=new Student();