Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Class notes Java

Rating
-
Sold
-
Pages
28
Uploaded on
24-03-2026
Written in
2025/2026

This helps you to understand and learn java. This document gives you more eloborate details of java. Thank you.

Institution
Course

Content preview

Unit II


Classes, Objects and Methods : Defining a Class – Creating Objects – Accessing

class members – Constructors – Method Overloading – Static Members –

Inheritance – Extending a Class – Overriding Methods – Final variables and

methods – Final Classes – Finalizer methods – Abstract Methods and Classes –

Methods with Varargs – Visibility Control – Arrays, Strings and Vectors – Onedimensional Array –
Creating an Array – Two-dimensional Arrays – Strings –

Vectors – Wrapper Classes – *Enumerated Types*.




Classes, Objects and Methods
✓ Class is a collection of data(variables) and methods that operate on that data
✓ A class is a user defined data type with a template that serves to define its properties.
✓ Class is a template for an object and an Object is an instance of a class

Defining a Class

class classname
{
[ Fields declaration;]
[ methods declaration;]
}

1.Fields Declaration
✓ Data is encapsulated in a class by placing data fields inside the body of the class
definition. These variable called instance variables, because they are created when the
object of the class is instantiated

class Rectangle
{
int length;
int width;
}

1

, ✓ The class Rectangle contains two integer type instance variables.

✓ It is allowed to declare them in one line int length, width

These variables only declared and therefore no storage space has been created in the memory.

2.Methods Declaration
✓ A method is a series of statements that carry out a task

✓ A class with only data fields(and without methods that operate on that data) has no
life. We must therefore add methods that are necessary for manipulating the data
contained in the class. Methods are declared inside the body of the class , but
immediately after the declaration of instance variables.

Syntax:
Type method name ( parameter – list)
{
method- body;
}

Method declaration must include:
1.A declaration (The name of the Method.)
2.The type of the value the method returns. (type)
3.A list of parameters (parameters-list)
4.The body of the method

Example:
class Rectangle
{
int length;
int width;
void getData(int x, int y)
{
length = x;
width=y;
}
int rectArea()
{
int area=length * width;
return(area);
}
}




2

, Creating Objects
✓ An object is a particular instance of a class.
✓ An object in Java is essentially a block of memory that contains space to store all
instance variables.
✓ Creating an object is also referred to as instantiating an object.
✓ Objects in Java are created using the new operator.
✓ The new operator created an object of the specified class and returns a reference to
that object.

Here is an example of creating an object of type Rectangle.
rectangle rect;
rect = new rectangle ();
or
rectangle rect = new rectangle ();
We can create any number of objects for a class.
Eexample:
rectangle rect1 = new rectangle ();
rectangle rect2 = new rectangle ();

Accessing Class Members
✓ Object members (fields and methods) are accessed with a dot between the object
name and the member name.

Objectname.varibale name;
Objectname.methodname (parameter – list)
Example , if we take the Rectangle class
rect1.length=15;
rect1.width=10;
The same way methods also called through object;
Rectangle rect1=new Rectangle() // creating an object
rect1.getData(15,10);

Applications of Classes and Objects
Example:
class Rectangle
{
int length;
int width;
void getData(int x, int y)

3

Written for

Institution
Secondary school
Course
School year
1

Document information

Uploaded on
March 24, 2026
Number of pages
28
Written in
2025/2026
Type
Class notes
Professor(s)
Sam
Contains
All classes

Subjects

$6.59
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sameer13

Also available in package deal

Get to know the seller

Seller avatar
sameer13
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 month
Number of followers
0
Documents
3
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions