0% found this document useful (0 votes)
47 views9 pages

Java Class and Object: by Madhumeeta Bhatia

This document provides an overview of classes, objects, methods, and constructors in Java. It defines a class as a template that contains variables, methods, and constructors. An object is an instance of a class that is used to access the class's properties and methods. Methods are functions that contain declarations and definitions, and can take parameters or return values. Constructors are used to initialize objects. The document provides examples to demonstrate how to define a class with variables and methods, create objects, and call methods.

Uploaded by

Diva Kar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
47 views9 pages

Java Class and Object: by Madhumeeta Bhatia

This document provides an overview of classes, objects, methods, and constructors in Java. It defines a class as a template that contains variables, methods, and constructors. An object is an instance of a class that is used to access the class's properties and methods. Methods are functions that contain declarations and definitions, and can take parameters or return values. Constructors are used to initialize objects. The document provides examples to demonstrate how to define a class with variables and methods, create objects, and call methods.

Uploaded by

Diva Kar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 9

Win Java Training Program

Java Class and Object

By
Madhumeeta Bhatia
Contents

 Class and An Object


 Method
 Constructor
 Garbage collection

www.wincorporatetraining.com 2
Java Class
 Template which contains variables, methods,
constructors and properties.
 Syntax
class <classname> {
// variable
// method
// constructor
}
 Variable – Object Property
 Methods – Object Functionality

www.wincorporatetraining.com 3
Java Class

 Write a program to define a class “Emp” with the


variable empno and ename.
 Define a Method called assign – to store the value
in the variable.
 Define a Method showInfo() – to print the
employee details.

www.wincorporatetraining.com 4
Object

 Instance of a Class.
 Used to access the properties and methods of the
class.
 Syntax [To Create Object]
<class name> <object Name> = new <constructor
name>();
 Example
Employee objE = new Employee();
Note: new operator dynamically allocates
memory for the object.

www.wincorporatetraining.com 5
Method

 Called as function in C and C++.


 Contains two parts
 Method Declaration
void showInfo();
 Method Definition
void showInfo() {
// java statements
}

www.wincorporatetraining.com 6
Method

 Purpose
 To Assign value
 To Perform calculation
 To Print the Output.
 Takes Parameters
void assign(int empno, String eno) {
……
……
}

www.wincorporatetraining.com 7
Method

 Method returns a Value


int Sum() {
return a+b;
}
 Called by using Object of the class.

www.wincorporatetraining.com 8
Class Diagram

Employee

Empno:int
Ename:String

Assign():void
showInfo():void

www.wincorporatetraining.com 9

You might also like