3 Oop
3 Oop
Programming Concepts
What is a class
What Is Inheritance?
What Is an Interface?
What Is a Package?
Java Features cont’d
• Java is both, compiled and interpreted
+ compiler
JVM + Libraries
+ utilities
JRE
JDK
Java Features cont’d
• Java is fully Object Oriented
Made up of Classes.
No multiple Inheritance.
• Java is a multithreaded language
You can create programs that run multiple threads of execution in parallel.
Ex: GUI thread, Event Handling thread, GC thread
• Java is networked
Predefined classes are available to simplify network programming through
Sockets(TCP-UDP)
Questions and Exercises: Object-Oriented Programming Concepts
1.Real-world objects contain ___ and ___.
2.A software object's state is stored in ___.
3.A software object's behavior is exposed through ___.
4.Hiding internal data from the outside world, and accessing it only through
publicly exposed methods is known as data ___.
5.A blueprint for a software object is called a ___.
6.Common behavior can be defined in a ___ and inherited into a ___ using
the ___ keyword.
7.A collection of methods with no implementation is called an ___.
8.A namespace that organizes classes and interfaces by functionality is
called a ___.
9.The term API stands for ___?
Lesson: Classes and Objects
Declaring Classes
Declaring Member Variables
• There are several kinds of variables:
• Member variables in a class—these are called fields.
• Variables in a method or block of code—these are called local
variables.
• Variables in method declarations—these are called parameters
The Bicycle class uses the following lines of code to define its fields:
public int cadence;
public int gear;
public int speed;
The first (left-most) modifier used lets you control what other classes have access to a member
field. For the moment, consider only public and private. Other access modifiers will be
discussed later.
•public modifier—the field is accessible from all classes.
•private modifier—the field is accessible only within its own class.
Types
1- All variables must have a type. You can use primitive types such as int, float, boolean, etc.
• In this lesson, be aware that the same naming rules and conventions
are used for method and class names, except that
• the first letter of a class name should be capitalized, and
• the first (or only) word in a method name should be a verb.
Defining Methods
1.Declaration: The code set in bold are all variable declarations that associate a variable name with an
object type.
2.Instantiation: The new keyword is a Java operator that creates the object.
3.Initialization: The new operator is followed by a call to a constructor, which initializes the new object
Declaring a Variable to Refer to an Object
type name;
Point originOne;
Instantiating a Class
Initializing an Object
Using Objects Referencing an Object's Fields
Calling an Object's Methods