Class 1
Class 1
==================================================================================
2. Create a class Moive with following details
1.movieName
2.heroName
3.heroineName
4.cost
5.noTicekts
===================================================================================
===
3. create a class ICICIBank with following details
1. branchName
4. transactionDate
b. create a metho setData which will set balance=1000 and transaction date as
today
===================================================================================
====
System.debug('Branch :'+branch);
System.debug('accountNo:'+accountNo;
}
public void setData(){
balance=1000;
transactionDate=System.today();
}
}
-----------------------------------------------------------------------------------
------
Contructor :
1. This is a special method defined with in the class with the same name of the
class
Syntax :
public /global class ClassName{
public/global className(parameters){
==================================================================================
Example 1: public class Example{
public Example(){
}
}
public Movie(){
}
}
Example 4: Create class Movie with a constructor which has movieName and cost as
parameter
}
}
===================================================================================
====
Example 5: Create a class Book with
1.bookName
2.authorName
bookName='3states';
authorName='ChetanBhagat';
}
}
===================================================================================
==
Example 6 : Create class InvoiceItems
2. amount
3. branch
->In this method price should be added to amount and display the
amount
===================================================================================
====
public class InvoieItems{
public InvoieItems(){
invoiceNo='CI001';
amount=0;
branch='SRNagar';
}
public void submit(Decimal price){
amount=amount+price;
System.debug('Amount :'+amount);
}
}
===================================================================================
a. productName
b. price
c. quanity
d. productInfo() : assign the value in the constructor
e. show() : Which will display the data memebers of the class
public ProductInfo(){
productName='Dell';
quanity=2;
price=20000;
}
System.debug('Name :'+productName);
System.debug('Price :'+price);
System.debug('Quanity:'+quanity);
}
}
Debug Console :
ProductInfo p1=new ProductInfo();
p1.show();
ProductInfo p2=new ProductInfo();
p2.show();
==========================================================================
1. collegeName
2. branch
3. phone
4. name
5. StudentDetails(sname,sphone) :
assign the collegename as 'CBIT'
branch as 'CSE'
Create two objects for StudentDetails and invoke show() method on them
===================================================================================
=====
Debug :
StudentDetails s1=new StudentDetails('Ravi','123');
s1.show();
StudentDetails s2=new StudentDetails('Kiran','456');
s2.show();
===================================================================================
===
Example 9:
1. invoiceDate
2. total
3. tax
4. available
5. cost
6. Invoice(savailable) : invoiceDate as today
total=0
tax=0
7. placeOrder(quanity) :
Debug:
Invoice inv=new Invoice(100);
inv.placeOrder(40);
===================================================================================
==
Example 10 :Create a class Employee
1. empName
2. salary
3. exp
4. Employee(empName,salary,exp)
5. calculate() : This method will calculate the bonus and print the
bonu value
this.empName=empName;
this.salary=salary;
this.exp=exp;
}
public void calculate(){
Decimal bonus=0;
if(exp > 10){
bonus=salary*0.20;
}else{
bonus=salary*0.10;
}
System.debug('Bonus value :'+bonus);
}
e1.calculate();