What is Class in Java and Object Oriented Programming
Class and Object are two pillars of OOPS languages, see here http://javarevisited.blogspot.sg/2011/10/class-in-java-programming-general.html
or <a>Java67 Blog</a>
What is Class in Java and Object Oriented Programming
1.
What is Classin Java
Programming
http://javarevisited.blogspot.com
2.
What is Classin Java
• Are you familiar with date types like int, long,
float?
• If Yes, than what is the limitation of these
data types?
• You got it right, they can only hold one type
of data, i.e an int can only store integer
values, a float can only store floating point
values.
3.
What is Classin Java
• Then question comes, how do we
represent user defined types e.g.
Person which can have a String name, a
long phone number and an int age
• Class in Java is way to go.
• Class in Java is used to create user
defined types.
4.
What is Classin Java
• Benefit of user defined type is that it
can combine and store multiple type and
gives you power to create a user
defined type for anything which exists
in real world.
• You can divide them into two category.
• JDK or System classes and Application
Classes
5.
What is Classin Java
• JDK Classes are those which comes
along with JDK e.g. java.lang.String,
java.lang.Thread
• Application classes are those which you
create in your Java program or
application e.g. Person, Student etc
• Class in Java is created using class
keyword
6.
What is Classin Java
Here is an example of user defined class
class Person{
int age;
String name;
long phone;
public void int getAge(){
return age;
}
}
7.
What is Classin Java
• Except holding code for variables e.g.
age, name and phone and methods e.g.
getName(), class doesn’t do any thing.
• Real magic starts when you create
object of class.
• For example every single person e.g.
you, me and your friend are object of
Person, they have different name, age
and phone number but they are Person
8.
What is Classin Java
• Object are actual thing which is created
from blueprint called class.
• Just like every car including BMW,
Merc and Audy has blueprint and follow
specification, every object follows
structure defined in class.
• We learn more about object in Java in
our next presentation.
9.
What is Classin Java
• In Summary you can say a Class in Java
is
– A user defined type
– A way to combine multiple data types into
one
– A blueprint to create object
– A structure to hold variables and methods
together
10.
Related Articles andPost
• For more details on Class and Object in
Java, See :
• What is Class in Java programming language
• What is Object in Java programming language
• Website: http://javarevisited.blogspot.com /