Introduction To Java Object Oriented Programming

Introduction To Java Object Oriented Programming – In this article we are going to talk about Java Object Oriented Programming.

So Object-oriented programming (OOP) is one of the bigger programming buzzwords of recent
years, and you can spend years learning all about object-oriented programming methodologies
and how they can make your life easier than The Old Way of programming. It all comes down
to organizing your programs in ways that echo how things are put together in the real world.

 

 

1: Check Java Basics Tutorial

2: Python Basic Tutorial

3: PyQt5 GUI Development

What does this have to do with programming?

Everything. Object-oriented programming
works in exactly this same way. Using object-oriented programming, your overall program is
made up of lots of different self-contained components (objects), each of which has a specific
role in the program and all of which can talk to each other in predefined ways.

 

 

Objects and Classes

Object-oriented programming is modeled on how, in the real world, objects are often made up
of many kinds of smaller objects. This capability of combining objects, however, is only one very
general aspect of object-oriented programming. Object-oriented programming provides several
other concepts and features to make creating and using objects easier and more flexible, and the
most important of these features is that of classes.

So A class is a template for multiple objects with similar features. Classes embody all the
features of a particular set of objects.

 

When you write a program in an object-oriented language, you don’t define actual objects. You
define classes of objects.

 

Behavior and Attributes

Every class you write in Java is generally made up of two components: attributes and behavior.
In this section, you’ll learn about each one as it applies to a theoretical class called Motorcycle.
To finish up this section, you’ll create the Java code to implement a representation of a
motorcycle.

 

Attributes

Attributes are the individual things that differentiate one object from another and determine th
appearance, state, or other qualities of that object. Let’s create a theoretical class called
Motorcycle. The attributes of a motorcycle might include the following:

 

  • Color: red, green, silver, brown
  • Style: cruiser, sport bike, standard
  • Make: Honda, BMW, Bultaco

 

Attributes of an object can also include information about its state; for example, you could have
features for engine condition (off or on) or current gear selected.

 

Attributes are defined by variables; in fact, you can consider them analogous to global variables

for the entire object. Because each instance of a class can have different values for its variables,
each variable is  instance variable.

 

Instance Variable

Instance variables define the attributes of an object. The class defines the kind of attribute,
and each instance stores its own value for that attribute.

 

Behavior

A class’s behavior determines what instances of that class do when their internal state changes
or when that instance is asked to do something by another class or object. Behavior is the way
objects can do anything to themselves or have anything done to them. For example, to go back
to the theoretical Motorcycle class, here are some behaviors that the Motorcycle class might have:

 

  • Start the engine
  • Stop the engine
  • Speed up
  • Change gear
  • Stall

 

 

How To Create Class In Java ?

 

So in the above code we have created a Motorcycle class. this class has attributes and behaviors, let me complete the code and run the code for the class.

Also i have add a new method in this class

 

 

 

Run the code and this will be the result

 

Introduction To Java Object Oriented Programming
Introduction To Java Object Oriented Programming

Subscribe and Get Free Video Courses & Articles in your Email

 

Codeloop
Share via
Copy link
Powered by Social Snap
×