0% found this document useful (0 votes)
81 views5 pages

Concept of Objects and Classes

This document discusses key concepts in object-oriented programming including objects, classes, abstraction, encapsulation, inheritance, and polymorphism. It defines an object as an instance of a class that represents a real-world entity with attributes and behaviors. A class acts as a blueprint for objects, defining their common properties and methods. Object-oriented programming focuses on data rather than procedures through these core concepts.

Uploaded by

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

Concept of Objects and Classes

This document discusses key concepts in object-oriented programming including objects, classes, abstraction, encapsulation, inheritance, and polymorphism. It defines an object as an instance of a class that represents a real-world entity with attributes and behaviors. A class acts as a blueprint for objects, defining their common properties and methods. Object-oriented programming focuses on data rather than procedures through these core concepts.

Uploaded by

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

Concept of Objects and Classes

DEVELOPMENT OF COMPUTER LANGUAGE:


Computer are basically a problem solving device capable of performing computations and making logical
decisions. Computer basically understands only machine language i.e. the binary language or the language of
the 0’s and 1’s.
Machine language is very difficult to program and interpret so assembly languages were developed as
symbolic representation of binary code. Though better than machine code assembly code was also difficult to
program and debug. This eventually led to the development of High Level Languages(HLL).
You have different approach like:
Monolithic Programming: Programs consists sequential code and global(available to the entire program)
data. It is suitable for developing small and simple applications. E.g. Assembly language and BASIC.

Procedural Programming: Programs are organized in the form of subroutines(sub-programs/functions) and


data is available to all the sub-programs. Primary focus is on procedure. This programming approach is
suitable for medium sized software applications. E.g. COBOL and FORTRAN.

Object Oriented Programming: OOP focuses on data rather than procedure and structure. This is a
method where programming is adjusted and modeled on the basis of real life entities and processes.
E.g. C++, Smalltalk ,Java
Characteristics of Oriented Programming:
 Programs are divided into what are known as objects.
 Data is hidden and cannot be accessed by external methods/functions.
 Addition of new data and functions can be done easily whenever necessary.

BASIC CONCEPT OF OBJECT- ORIENTED PROGRAMMING:


Object - Object is a real world entity i.e. anything that is tangible, can be seen or imagined. Student, car,
book, mobile, bank account, quadrilateral, table, chair etc are all objects. Each object can be thought of a
bunch of attributes (characteristics) and different operation perform on this bunch of attributes i.e. its
behaviour.
Ex. Nokia N73 is an instance of class Cellphone, Maruti is an instance of the class car.

Class - A class is a prototype or blueprint or layout that defines how an instance of that class should be
i.e. a class is template according to which objects of that class are created.
A class is a group of objects that share common properties, relationship and behaviors.
Thus mobile is a class and Nokia N73 etc are objects of this class.

Abstraction - Abstraction is a way to manage the complexity of any system. Abstraction refers to the act
of representing the essential features without including the complexity of background details.
Ex. While using your computer system you need to know the basic operations of putting on, shutting down
and knowledge to use the peripherals. You need not know the internal functioning or the complex
architecture of the system
Encapsulation - The wrapping up of data and functions into a single unit called is known as
encapsulation.
Encapsulation is a way of implementing abstraction. Encapsulation is a mechanism that associates the code
and data it manipulates and keep them safe from outside interference and misuse.

Inheritance - Inheritance is a process by which a class called derived class/sub class/child class inherits
properties of another class called base class/super class/parent class.
Greatest advantage of inheritance is code reusability. Java used the extends keywords to set the relationship
between derived class and base class. Derived class uses keyword super to refer to the members of the base
class.
Ex:
Vehicle

Four Wheeler

Car

Swift

Software Objects - A software object is a collection of variables, which represent the attributes and
related methods which implement the behaviour.
The current values of instance variables define the state of an object. Software objects represent the
attributes through variables called instance variable.

Account

accountNumber Withdraw()
clientName
accountType accountNumber
E enquire()
clientName
balance accountType
Deposit( ) balance
Withdraw( ) deposit()
Enquire( )

Polymorphism - Polymorphism has been derived from Greek word polymorphous i.e. Polus (many)
morpha (form). Thus polymorphism means having many forms.
When same message is sent to different objects. The interpretation of the message and response generated
will be different. This is termed as polymorphism.
Ex. ‘+’ when used with numbers results in their addition: 3+7 gives 10. When use with strings results in their
concatenation: “good” + “morning” gives good morning
Q.1: Explain a class as an object factory?
Ans: A class represent a group of objects of the same kind. Ex. Class of cellphone represent Samsung j7, Nokia
N73 etc. Class of car represent – Zen, Ford, SUV etc. Objects with the same attributes (Structure, name, Size…)
and behaviours (function) are grouped into a class. Each class can produced number of objects, So it can be
called a factory of objects.

Q.2: What is Attributes?


Ans: An attributes is a data value hold by the objects in a class. Ex. Name, age, height, weight are the
attributes of a class person. Model, color, price, weight are the attributes of the object of class Car.

Q.3: Mention any two attributes required for class declaration?


Ans: Attributes of a class can be primitive type and reference type. To complete a class, we need to specify
data (variable) members, and member (methods) functions.

Q.4: Differentiate between base class & derived class?


Ans: Base class is a super class whose members are inherited.
Derived class is a subclass the inherits the ember function of base class.
Ex. Class A Here A is base class and
{ B is derived class.
--------
--------
}
Class B extends A
{
--------
--------
}
Q.5: What are methods? How are there related to an objects?
Ans: The data is accessed through the member functions of the objects. These members functions are known
as methods. Methods are very closely linked to the object in an object oriented programming structure.
In this type of programming concept, you cannot access the data directly. You can access the data by the help
of methods, and method can be accessed by the help of objects.

Q.6: How are objects related to class?


Ans: An object is an identifiable entity with some character and behavior. These are the instance of the class.
Group of objects having similar state and behaviors are combined to form a class.

Q.7: What is a message?


Ans: When the objects need to interact with one another. They pass request information to one another. This
is known as message passing.
Q.8: Write down the features of OOPS Structure?
Ans: (i) The complete solution of the problem is divided into some objects.
(ii) In each object separate data exists which normally cannot be changed by other object.
(iii) The existing object many interact or communicate with each other.

TYPE CONVERSION: The process of conversion of one data type to another data type is called type conversion.
There are two type of conversion in java.
1. Implicit type conversion:- This is a conversion which is done by compiler without programmer intervention.
Implicit type conversion is performed automatically. Whin an expression contains operand of different types,
lower types are automatically converted to higher types. This is also referred to as type promotion
Ex. char ch= ‘a’; 97 * Destination is larger than source
int x= 7 * The two types are compatible
Sopln( ch + x); ----->

2. Explicit type conversion: This type of conversion is exclusively done by the user. User can convert all the
operands to any specific type. This is also referred to as type casting.

Ex. double p = (double ) x/y; * Destination smaller than source


* The two types are compatible
Here x may be integer and y may be double, but the expression will be in double.

ESCAPE SEQUENCES: These are non-printable characters, they cannot types directly from keyboards.
Ex. \n (next line), ‘\b’ (backspace), ‘\t’ (tab) etc.

HANDLING STRINGS IN JAVA: Strings can be stored in variables of the string type. String is not a primitive type
but a class. String objects can be constructed in number of ways:
(i) Using String Literals:- A String can be created from a String literal. E.g. String s= “HELLO”;
Above statement create a string object s with value HELLO.

(ii) Using new keyword:- String object can be create like other object using new keyword.
String s1=new String (“INDIA”);

(iv) Using character Array:- String object can be create using character array.
E.g. char ch[ ]= {‘H’ , ‘E’ , ‘L’ , ‘L’ , ‘O’};
String str = new String (ch);
Above statement create a string object str, from character array ch[ ] , thus str contains HELLO.

DECLARING A VARIABLE : In java all variables must be declared before they are used. The general form of
variable declaration in given below:
int x,y,z ; // declare 3 int type variable
int a=5, b, c=10; // declare 3 int type variable & initialize 2
double p=3.14159; // declare a double type variable & initialize.

DYNAMIC INITIALIZATION : Java allows variable to be initialize during the execution of program.
int a = 16; //simple initialization
int b = a*a ; // dynamic initialization
double c= Math.sqrt(b); //dynamic initialization
THE SCOPE AND LIFETIME OF VARIABLES: Java allows variable to be defined inside any block enclosed in
curly braces. A block define a scope. The scope determine, what the area over which variable is accessible.
Lifetime of a variable refers to the duration for which a variable exists in the computer memory “Scope
generally refers to the program region within which a variable is accessible”.

WRAPPER CLASSES: Java provide classes that correspond to each other of the simple type. There classes
encapsulate, (or wrap) the primitive type within a class. Thus they are referred to as type wrapper. Wrapper
classes are available for all primitive data type.
NON- PRIMITIVE OR REFERENCE DATA TYPE: Reference in java is a variable whose value is an address.
E.g: int a =5; Here variable a has been initialized to value 5. This value (5) is called rvalue (actual read value)
and the memory location of variable a is known as lvalue (location value).

Reference data type deal with lvalue, Array, Classes and interfaces are reference data type. This arrays, object
and interfaces are references i.e. contain address of location instead of value stored at that location.

INTERFACE: An interface is used as a protocol of communication between objects. An interface is a set of


variables and methods like a class.

Types of Variable in Java : Java support 3 kinds of variables.

1. INSTANCE VARIBALE: Objects store their individual states in variables called instance variable. Each
object of the class has its own set of values for these variables. Thus we can say that these are related
to objects(instance of the class). Hence these variables are known as instance variables.
These variables take default values if not initialized.
2. Class Variables (Static fields): These are related to a class and none of the individual objects. The
variables defined with static keywords are shared by all objects. Here objects do not store an individual
value but they are forced to share it among themselves. These variable are declared as “static fields”
using the static keywords. So these variable are like global variable which are same for all objects of the
same class.
3. Local Variables: The variables defined in a method or block of code only. These variables don’t take
default values if not initialized. These values are required to be initialized before using them.

Programming Solution Point


PIYUSH SIR (8273651685)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy