0% found this document useful (0 votes)
51 views14 pages

CO - IF - 22412 - CO1: Date: 05 February 2021 Learning at Your Doorstep

The document is a lesson on creating classes and objects in Java. It defines a class as a template for objects and explains that objects are instances of classes. It provides three key steps for creating objects: 1) Declaring an object variable, 2) Instantiating an object using the "new" operator, and 3) Initializing an object by calling a constructor. The document also explains how to define a class and access class members using dot notation. The overall purpose is to teach students the basic concepts and syntax for defining classes and creating objects in Java.

Uploaded by

Vinayak Khade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views14 pages

CO - IF - 22412 - CO1: Date: 05 February 2021 Learning at Your Doorstep

The document is a lesson on creating classes and objects in Java. It defines a class as a template for objects and explains that objects are instances of classes. It provides three key steps for creating objects: 1) Declaring an object variable, 2) Instantiating an object using the "new" operator, and 3) Initializing an object by calling a constructor. The document also explains how to define a class and access class members using dot notation. The overall purpose is to teach students the basic concepts and syntax for defining classes and creating objects in Java.

Uploaded by

Vinayak Khade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

CO_IF_22412_CO1

Ms. Yogita Jore, Head of Information Technology, Vidyalankar Polytechnic

Date: 05th February 2021

Learning at your doorstep


Unit 1:
Basic Syntactical constructs in Java

Written by

Yogita Jore
Head, Department of Information Technology (NBA Accredited),
Vidyalankar Polytechnic, Mumbai
Unit Outcome 1:
Write a program to create classes and
objects for the given problem.
Learning Outcome 1c:
Students should understand the
concept of Classes and Objects.
What we will learn today-Class and Objects

Key takeaways
1. Defining class
How to create object and class in Java?
2. Creating objects

3. Accessing Class Members

Yogita Jore
Head, Department of Information Technology (NBA Accredited), Vidyalankar Polytechnic,
Mumbai

Page 5 Maharashtra State Board of Technical Education


Concept Map

Page 6 Maharashtra State Board of Technical Education


Learning Objective/ Key learning

► Creating Object and Class

Page 7 Maharashtra State Board of Technical Education


Defining a Class:

 user defined data type.


 Once a new data type is defined using a class, it can be used to create objects of that type.
 A class is a template for an object and object is an instance of a class.
 Classes create objects and objects use methods to communicate between them.
Syntax:
class classname [ extends superclassname]
{
[ fields declaration; ]
[ methods declaration; ] Example:
} class rectangle
{
int length, width; //declaration of variables
void getdata(int x, int y) //definition of method
{
length = x;
width = y;
}

Page 8 Maharashtra State Board of Technical Education


Object:

 It is a basic unit of Object-Oriented Programming and represents the real life entities.
 Object consists of following elements:
State: It is represented by attributes of an object. It also reflects the properties of an object.
Behavior: It is represented by methods of an object. It also reflects the response of an object with
other objects.
Identity: It gives a unique name to an object and enables one object to interact with other objects.

Page 9 Maharashtra State Board of Technical Education


Creating Objects:

 Steps for creating objects:


A. Declaring an object:
 Also called instantiating a class.
 When an object of a class is created, the class is said to be instantiated.
 Declaring a variable to hold an object is just like declaring a variable to hold a value of primitive
type.
 Declaration does not create new objects. It is simply variable that can refer to an object.
 For example: Rectangle rect1;

Page 10 Maharashtra State Board of Technical Education


Creating Objects:

 Steps for creating objects:


B. Instantiating an object:
 Creating an object is also referred to as instantiating an object.
 Objects in java are created using the new operator.
 The new operator creates an object of the specified class and returns a reference to that
object.
 For example: Rectangle rect1 = new Rectangle ();
 Assigns the object reference to the variable. The variable rect1 is now an object of the
rectangle class.

Page 11 Maharashtra State Board of Technical Education


Creating Objects:

 Steps for creating objects:


C. Initializing an object:
 Classes provide constructor methods to initialize a new object of that type.
 A class may provide multiple constructors to perform different kinds of initialization on new
objects.
 For example: Rectangle rect1=new Rectangle (10, 20);

Page 12 Maharashtra State Board of Technical Education


Accessing Class Members:

 We can access Class members by using dot operators.

Syntax:
objectname . variablename = value;
objectname . methodname (parameterlist);

Example:
rect1.length=10;
rect1.width=20;

//creating an object
Rectangle r1 = new Rectangle();

//calling the method using the object


r1.getdata(10,20);

Page 13 Maharashtra State Board of Technical Education


Problem/ Question Explanation and step by step Solution

Q1: Objects in java are created using the ______ operator.


Ans: new

Q2: Object is an instance of a _______.


Ans: class

Page 14 Maharashtra State Board of Technical Education

You might also like