The document discusses the basics of classes and objects in Java. It defines a class as a template for creating objects that have both data fields (attributes) and methods. An object is an instance of a class that contains specific values for its attributes and can execute the methods defined in its class. The document provides examples of defining a Rectangle class with length and width attributes and methods to set their values and calculate the area. It also demonstrates how to declare objects of the Rectangle class and access their attributes and methods.
Classes extend the built-in capabilities of C++ able you in representing and solving complex, real-world problems. A class is an organization of data and functions which operate on them. Data structures are called data members and the functions are called member functions, the combination of data members and member functions constitute a data
object or simply an object.
Class is a group of data member and member functions. Another word class is a collection of objects of similar type.
To create a class, use the class keyword followed by a name for the object. Like any other declared variable, the class declaration ends with a semi-colon. The name of a class follows the rules we have applied for variable and function names.
Class object method constructors in javaRaja Sekhar
Presented By :
N.V.Raja Sekhar Reddy
www.technolamp.co.in
www.programming9.com
Want more interesting...
Watch and Like us @ https://www.facebook.com/Technolamp.co.in
subscribe videos @ http://www.youtube.com/user/nvrajasekhar
Classes extend the built-in capabilities of C++ able you in representing and solving complex, real-world problems. A class is an organization of data and functions which operate on them. Data structures are called data members and the functions are called member functions, the combination of data members and member functions constitute a data
object or simply an object.
Class is a group of data member and member functions. Another word class is a collection of objects of similar type.
To create a class, use the class keyword followed by a name for the object. Like any other declared variable, the class declaration ends with a semi-colon. The name of a class follows the rules we have applied for variable and function names.
Class object method constructors in javaRaja Sekhar
Presented By :
N.V.Raja Sekhar Reddy
www.technolamp.co.in
www.programming9.com
Want more interesting...
Watch and Like us @ https://www.facebook.com/Technolamp.co.in
subscribe videos @ http://www.youtube.com/user/nvrajasekhar
chapter 1: Lecture 2
Let’s think on concept of Class and Object
- Concept of Objects and classes
- UML Class Diagram
الكلية الجامعية للعلوم والتكنولوجيا - خان يونس
University college of science & technology
Classes, Objects and Method - Object Oriented Programming with JavaRadhika Talaviya
Class is template for an object and object is instance of a class.
When we create a class, we are creating a new data type. we can use this type to declare objects of that type.
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
OOPS and its application in Java, Super class AND This Keyword,Java Bean, POJO ,Memory management in Java ,Packages ,Miscellaneous (Var-Args, toString(), Double equals operator(==))
2. Objectives
On completion of this period, you would be able to
learn
• Class
• General form of class
• Object
2
3. Recap
• In the previous class we learnt
• Language basics like
Selection statements
Iterative statements
Break and continue statements
4. Class Fundamentals
WWhat is an entity ?
• Anything that is uniquely identifiable
• It has attributes, which describe the entity
• If we provide methods to such entity
• We get a class
4
5. Class Fundamentals …contd
Regarding the structure of a class
O How is ‘struct’ in C language designed ?
• It is a collection of heterogeneous types of data items
• A list variables are put together
• If we add methods (functions) to it, we get something
equivalent to a class
5
6. Class Fundamentals contd
• Class
• Class is a template for an object
• It defines a new data type
• It contains data members and related methods
Examples of class
• Student
• Employee
• Rectangle
6
7. General Form Of A Class
• While defining declare exact form and nature
• Specify the data and code that operates it
• Data declared in a class are called ‘instance variables’
• Simple class contains only code or only data
• Real world classes contain both code and data
• Class is declared by keyword ‘class’
7
8. General Form Of Class contd..
User defined name
Syntax:
class classname {
type instance-variable1;
type instance-variable2;
--- ---
--- ---
type instance-variable N;
type methodname1(parameter-list) {
(body of method)
}
8
9. General Form Of Class contd..
type methodname2(parameter-list) {
(body of method)
}
--- ---
--- ---
type methodnameN(parameter-list) {
(body of method)
}
}
9
10. Discussion
• Compare the structure in C with class in Java
• Only data members are permitted in struct
• Data and methods are permitted in class
• Visibility control is not there in struct
• Visibility control is available
10
11. Example
Class name – Box
Instance variables – width, height and depth
As class defines a type of data,
class Box { Here new data type is Box
double width;
double height;
double depth;
}
11
12. Discussion
• List some more class examples with their data
and method members
• Product
– prodId, prodDesc, price, qty
– receive(), issue() [ in store environment]
• Bike
– model, regNo, color, cost, milage
– start(), stop(), accelerate(), applyBreak()
12
13. Object – Definition
Object
• A software bundle of data and the related
methods
• Object is an instance of a class
• Object contains both state and behaviour
• State means its data members containing
specific values
• Behaviour means the collection of methods
defined in the object
13
14. Object – Definition contd..
• Examples
• State
• A student with PIN 004-CM-601
• An employee with an id EMP608
• A rectangle with length 15 and width 8
• Behaviour
• setMarks(), getMarks(String PIN)
• computeSalary()
• computeArea(), setLength(),setWidth()
14
15. Creating Object
Creating Object
• There are two steps to create an object
• Declare object
• Allocate memory and initialize the object
Syntax for declaring object
• ClassName objectName;
• eg. Box myBox;
Syntax for allocate memory and initialize
• objectName = new ClassName()
• eg. myBox = new Box();
15
17. Example On Classes And Objects
class Rectangle {
int length , width; //declaration of variables
void getData(int x, int y) //definition of method
{
length = x;
width = y;
}
int rectArea() //definition of another method
{
int area = length * width;
17
18. Example On Classes And Objects contd..
return(area);
}
}
class Rectarea // class with main method
{
public static void main(String args[])
{
int area1,area2;
Rectangle rect1 = new Rectangle(); //creating objects
18
20. Output of Program
Area1 = 150 // Through Accessing variables
Area2 = 240 // Through accessing methods
20
21. Summary
In this class we have discussed
• Class
• General form of a class
• Object
21
22. Quiz
1. Among the following which is keyword to declare
a class ?
a) new
b) object
c) type
d) class
22
23. Quiz Contd..
2 .To access member of a class which operator is
used ?
a) &
b) . (dot)
c) *
d) +
23
24. Quiz Contd..
3. Object is
a) Inheritance of a class
b) Instance of a class
c) Subclass of a class
d) Super class of a class
24
25. Frequently Asked Questions
1. What is a class ?
2. Mention the key word to declare a class
3. What are the common components of a class?
4. What is an object?
5. Write a program in Java for declaring a class and object
25
26. swings
Struts
jdbc
hibernate
home
java previous question papers
OCT/NOV-2012 QUESTION PAPER
April / May 2012 c-09
October/ November-2011 c-09
April/ May 2011 c-09
April/ May 2011 c-05
Home 26