0% found this document useful (0 votes)
28 views43 pages

3 Oop

Uploaded by

drchick4444
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views43 pages

3 Oop

Uploaded by

drchick4444
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

Object-Oriented

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

compile Interpret JVM


Source Intermediate
Run
Code One time Code Every Time
ONLY
MyFile.java MyFile.class
Java Features cont’d
• Java depends on dynamic linking of libraries

+ 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;

Field declarations are composed of three components, in order:


1.Zero or more modifiers, such as public or private.
2.The field's type.
3.The field's name.
Access Modifiers

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.

2- Or you can use reference types, such as strings, arrays, or objects.


Variable Names
• All variables, whether they are fields, local variables, or parameters,
follow the same naming rules and conventions that were covered in
the Language Basics lesson, Variables—Naming.

• 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

The signature of the method declared above is:


calculateAnswer(double, int, double, double)
Naming a Method
Providing Constructors for Your Classes
Overloading Methods
Parameter Types
Passing Information to a Method or a Constructor
Arbitrary Number of Arguments
Parameter Names
Passing Primitive Data Type Arguments
Passing Reference Data Type Arguments
Objects

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

You might also like