"Oops Concepts in Java" is a visually engaging and comprehensive guide to object-oriented programming in Java. Packed with clear explanations and illustrated with helpful diagrams and code snippets, this PDF will take you on a journey through the key concepts of object-oriented programming, from cl...
Learn OOPS concepts in Java with real time examples
and source code examples.
Object Oriented Programming Concepts are very important. Without having an idea about
OOPS concepts, you will not be able to design systems in the object-oriented programming
model. It simplifies software development and maintenance.
Let's discuss above each OOPS concepts with a real-world example.
1. Object
The Object is the real-time entity having some state and behavior. In Java, Object is
an instance of the class having the instance variables like the state of the object and
the methods as the behavior of the object. The object of a class can be created by
using the new keyword in Java Programming language.
A class is a template or blueprint from which objects are created. So, an object is the
instance(result) of a class.
I found various Object Definitions:
1. An object is a real-world entity.
2. An object is a runtime entity.
3. The object is an entity which has state and behavior.
4. The object is an instance of a class.
,Real-world examples
Dogs have state (name, color, breed, hungry) and behavior (barking, fetching,
wagging tail). Chair, Bike, Marker, Pen, Table, Car, Book, Apple, Bag etc. It
can be physical or logical (tangible and intangible).
Bicycles also have state (current gear, current pedal cadence, current speed)
and behavior (changing gear, changing pedal cadence, applying brakes).
, How to Declare, Create and Initialize an Object in
Java
A class is a blueprint for Object, you can create an object from a class. Let's take Student
class and try to create Java object for it.
Let's create a simple Student class which has name and college fields. Let's write a program
to create declare, create and initialize a Student object in Java.
package net.javaguides.corejava.oops;
public class Student {
private String name;
private String college;
public void setName(String name) {
this.name = name;
}
public String getCollege() {
return college;
}
public void setCollege(String college) {
this.college = college;
}
public static void main(String[] args) {
Student student = new Student("Ramesh", "BVB");
Student student2 = new Student("Prakash", "GEC");
Student student3 = new Student("Pramod", "IIT");
}
}
From the above program, the Student objects are:
Student student = new Student("Ramesh", "BVB");
Student student2 = new Student("Prakash", "GEC");
Student student3 = new Student("Pramod", "IIT");
Each of these statements has three parts (discussed in detail below):
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller abhisek05. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $6.48. You're not tied to anything after your purchase.