REPORT WRITING
NAME: PRATOY GHOSH
DEPARTMENT: BCA
SEMESTER: 3RD
ROLL NUMBER: 13301221019
SUBJECT CODE: BCAC301
TOPIC: JAVA CLASS AND OBJECT
INTRODUCTION
Definition of Class:
In object-oriented programing, a class is an extensible
program -code-template for creating objects, providing
initial values for state (member variables)
implementation of behavior (member functions or
methods).
Syntax:
public class Main {
int x = 6;
}
Definition of Object: An object in Java is the physical as well
as a logical entity, whereas, a class in Java is a logical entity
only. For example: in real life, a car is an object.
Syntax:
public class Main {
int x = 6;
public static void main(String[] args) {
Main myObj = new Main();
System.out.println(myObj.x);
}
}
BODY-
Next Topic :
//Java Program to demonstrate the working of a banking-system
//where we deposit and withdraw amount from our account.
//Creating an Account class which has deposit() and withdraw() methods
class Account {
int acc_no;
String name;
float amount;
//Method to initialize object
void insert(int a,String n,float amt) {
acc_no=a;
name=n;
amount=amt;
//deposit method
void deposit(float amt) {
amount=amount+amt;
System.out.println(amt+" deposited");
//withdraw method
void withdraw(float amt) {
if(amount<amt) {
System.out.println("Insufficient Balance");
else
{
amount=amount-amt;
System.out.println(amt+" withdrawn");
//method to check the balance of the account
void checkBalance()
System.out.println("Balance is: "+amount);
//method to display the values of an object
void display()
System.out.println(acc_no+" "+name+" "+amount);
//Creating a test class to deposit and withdraw amount
class TestAccount {
public static void main(String[] args) {
Account a1=new Account();
a1.insert(832345,"Ankit",1000);
a1.display();
a1.checkBalance();
a1.deposit(40000);
a1.checkBalance();
a1.withdraw(15000);
a1.checkBalance(); }}
CONCLUSION
The above program is a classic example of Class & Object Concept in Java. In this
program there is number of
Class->2(Account, TestAccount)
Variable: 3(acc no, name, amount)
Object: 1(a1) :Method: 5(deposit, insert, withdraw, checkBalance, display)
The term Object-Oriented explains the concept of organizing the
software as a combination of different types of objects that incorporates
both data and behavior. Hence, Object-oriented programming(OOPs) is a
programming model that simplifies software development and
maintenance by providing some rules.
Classes are required in OOPs because it provides template for creating
objects, which can bind code into data.
Objects are required in OOPs because they can be created to call a non-
static function which are not present inside the Main Method but present
inside the Class and also provide the name to the space which is being
used to store the data.
REFERENCES
Books:
PROGRAMMING IN Java – Sachin Malhotra & Saurabh
Choudhary
Websites:
https://WWW. W3schools.com/java/java_classes.asp