This document provides an overview of key concepts in Java including classes, objects, class members, packages, constructors, interfaces, abstract classes, object-oriented programming characteristics like encapsulation, inheritance, polymorphism and abstraction. It also discusses overriding, overloading, non-access modifiers, passing variables and strings. The presentation contains definitions and examples to explain each concept in 1-3 sentences.
Class is a blueprint for creating object instances that share common attributes and behaviors. It defines the variables and methods that are common to all objects of that class. When an object is created from a class, it is said to be an instance of that class. Objects contain state in the form of attributes and behavior in the form of methods. Classes in Java can define access levels for variables and methods as public, private, protected, or without a specified level (default).
Team Quadra presented on object-oriented programming concepts in Java, including abstraction, encapsulation, polymorphism, and inheritance. The team members are Nafiz Ar Rafi, Shohana Iasmin, MD. Maruf Hossain, Sinthia Sayeed, and Rokonuzzaman Razu. Examples were provided to demonstrate each OOP concept in Java code. Access modifiers and their usage were also discussed along with constructors and static variables.
This presentation provides an introduction to Java programming, covering key concepts like object-oriented programming (OOP) principles of objects, classes, inheritance, polymorphism, abstraction, and encapsulation. It also discusses Java features like platform independence and portability. Additionally, it defines common Java elements like data types, variables, methods, constructors, and operators.
This document provides an introduction to the Java programming language. It discusses the history and components of Java, including the Java language, platform, and tools. It then explains some key Java concepts like object-oriented programming, classes, objects, inheritance, and interfaces. It provides examples of how to write a simple Java program and declare methods. It also compares static and instance members and discusses abstract classes and when to use interfaces versus abstract classes.
1) Variables are used to store and represent data in a program. They have a name, data type, and range of values. Variable names must follow specific identifier rules.
2) Classes define the attributes (data) and behaviors (methods) of objects. An object is an instance of a class. Constructors are special methods that initialize new objects.
3) Constructors allow objects to be created and initialized with specific attribute values. Defining multiple constructors provides flexibility in how objects are instantiated.
Classes in Java represent templates for objects that share common properties and behaviors. A class defines the blueprint for objects, but does not use memory itself. Objects are instances of classes that represent real-world entities. For example, Dog is a class while Tommy is an object of the Dog class. Classes contain variables that store object data and methods that define object behaviors. Objects are declared by specifying the class name and are initialized using the new operator, which allocates memory and invokes the class constructor.
This document provides an overview of Java basics, including:
- Java is an object-oriented programming language and platform that allows code to run on many systems.
- Java code is compiled to bytecode that runs on a Java Virtual Machine (JVM).
- Key Java technologies include the JVM, Java Runtime Environment (JRE), and Java Software Development Kit (SDK).
- Java supports object-oriented programming concepts like classes, objects, inheritance, interfaces, and polymorphism.
- The document outlines language syntax rules and concepts like variables, methods, and access modifiers.
The document discusses abstraction, encapsulation, and classes in object-oriented programming. It defines abstraction as extracting common features while ignoring details. A class acts as an abstraction and template for objects, defining their attributes and behaviors. Encapsulation hides implementation details and controls access via setters and getters. Constructors initialize an object's state upon instantiation.
The document discusses key concepts of object-oriented programming (OOP) in Java, including objects, classes, inheritance, polymorphism, abstraction, and encapsulation. It provides examples of classes like Student and Rectangle to demonstrate how objects are instantiated from classes and how methods can access and modify object attributes.
This document provides an introduction to key object-oriented programming concepts in Java including abstraction, classes, objects, encapsulation, information hiding, access modifiers, constructors, and the toString() method. It defines classes as templates for objects that contain data and behavior, and objects as instances of classes that occupy memory. It also describes how encapsulation and information hiding are achieved in Java using access modifiers to hide implementation details while exposing public interfaces.
This document provides an overview of object-oriented programming concepts including abstraction, encapsulation, classes, objects, methods, constructors, inheritance, polymorphism, and interfaces. It explains that classes act as blueprints for objects, describing their data and behaviors. Objects are instances of classes that have state stored in attributes and behaviors defined by methods. Key features of OOP like inheritance, encapsulation, and polymorphism are discussed at a high level.
The document discusses object-oriented concepts in Java including objects, classes, constructors, encapsulation, and Java source file layout. It defines objects as anything real or conceptual and classes as blueprints for objects. Constructors are special methods that initialize objects. Encapsulation hides implementation details and protects data using private attributes with public getters and setters. The Java source file layout follows a PIC order of package, import, classes. It also discusses creating JAR files to package related class files together.
chapter 5 concepts of object oriented programmingWondimuBantihun1
The document discusses the basic concepts of object-oriented programming in Java, including objects, classes, abstraction, encapsulation, inheritance, and polymorphism. It provides examples of objects versus classes, creating objects, access modifiers, constructors, encapsulation with getter and setter methods, single inheritance, abstract classes and interfaces for abstraction, and method overloading and overriding for polymorphism.
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
The lecture was condcuted by Tushar B Kute at YCMOU, Nashik through VLC orgnanized by MSBTE. The contents can be found in book "Core Java Programming - A Practical Approach' by Laxmi Publications.
This document introduces object-oriented programming concepts. It defines objects as having state, behavior, and identity. Classes are templates that define common attributes and behaviors of objects. Inheritance allows subclasses to extend and specialize parent classes. Access modifiers like public, protected, and private control visibility of class members.
This document discusses key concepts in Java including abstraction, encapsulation, inheritance, polymorphism, and interfaces. It defines these concepts and provides examples. Abstraction hides unnecessary details and shows essential information. Encapsulation wraps data and functions into a single unit. Inheritance allows a subclass to acquire properties of another class. Polymorphism supports method overloading and overriding. Interfaces can be used to implement inheritance between unrelated classes and specify what a class must do without defining how. The document also discusses access specifiers, modifiers, variables, literals, and static and final keywords.
Java uses an object-oriented approach where data and methods are bundled together as objects. A class defines the common attributes and behaviors of a group of objects. Individual objects are instantiated from classes and can interact by sending messages that invoke each other's methods. Encapsulation hides an object's internal data within itself and controls access via public methods.
Java uses an object-oriented approach where data and methods are bundled together as objects. A class defines the common attributes and behaviors of a group of objects. Individual objects are instantiated from classes and can interact by sending messages that invoke each other's methods. Encapsulation hides an object's internal data within itself and controls access via public methods.
The document provides information about object-oriented programming concepts in Java including objects, classes, constructors, and access modifiers. It defines an object as having state, behavior, and identity. A class is described as a template or blueprint for creating objects that share common properties. The document discusses default and parameterized constructors. It also covers the static keyword in relation to variables, methods, blocks, and nested classes. Other topics include finalizer methods, import statements, and the four levels of access control in Java.
This document discusses object-oriented programming concepts. It defines an object as anything that can be represented by data and manipulated by a program. An object has properties that hold its data values and methods that manipulate the properties. A class is a blueprint that defines the properties and methods for instances of objects. The document provides examples of physical and non-physical objects and how they are represented by properties and methods in object-oriented programming.
This document provides an introduction to object-oriented programming concepts like classes, objects, and methods in Java. It defines classes as templates that define attributes and behaviors of objects as variables and methods. Objects are instances of classes. The document explains how to declare a class with access modifiers, variables, constructors, and methods. It also demonstrates how to create objects using the new keyword and access object attributes and methods.
14 Years of Developing nCine - An Open Source 2D Game FrameworkAngelo Theodorou
A 14-year journey developing nCine, an open-source 2D game framework.
This talk covers its origins, the challenges of staying motivated over the long term, and the hurdles of open-sourcing a personal project while working in the game industry.
Along the way, it’s packed with juicy technical pills to whet the appetite of the most curious developers.
How the US Navy Approaches DevSecOps with Raise 2.0Anchore
Join us as Anchore's solutions architect reveals how the U.S. Navy successfully approaches the shift left philosophy to DevSecOps with the RAISE 2.0 Implementation Guide to support its Cyber Ready initiative. This session will showcase practical strategies for defense application teams to pivot from a time-intensive compliance checklist and mindset to continuous cyber-readiness with real-time visibility.
Learn how to break down organizational silos through RAISE 2.0 principles and build efficient, secure pipeline automation that produces the critical security artifacts needed for Authorization to Operate (ATO) approval across military environments.
More Related Content
Similar to Classes and Object Concept Object Oriented Programming in Java (20)
The document discusses abstraction, encapsulation, and classes in object-oriented programming. It defines abstraction as extracting common features while ignoring details. A class acts as an abstraction and template for objects, defining their attributes and behaviors. Encapsulation hides implementation details and controls access via setters and getters. Constructors initialize an object's state upon instantiation.
The document discusses key concepts of object-oriented programming (OOP) in Java, including objects, classes, inheritance, polymorphism, abstraction, and encapsulation. It provides examples of classes like Student and Rectangle to demonstrate how objects are instantiated from classes and how methods can access and modify object attributes.
This document provides an introduction to key object-oriented programming concepts in Java including abstraction, classes, objects, encapsulation, information hiding, access modifiers, constructors, and the toString() method. It defines classes as templates for objects that contain data and behavior, and objects as instances of classes that occupy memory. It also describes how encapsulation and information hiding are achieved in Java using access modifiers to hide implementation details while exposing public interfaces.
This document provides an overview of object-oriented programming concepts including abstraction, encapsulation, classes, objects, methods, constructors, inheritance, polymorphism, and interfaces. It explains that classes act as blueprints for objects, describing their data and behaviors. Objects are instances of classes that have state stored in attributes and behaviors defined by methods. Key features of OOP like inheritance, encapsulation, and polymorphism are discussed at a high level.
The document discusses object-oriented concepts in Java including objects, classes, constructors, encapsulation, and Java source file layout. It defines objects as anything real or conceptual and classes as blueprints for objects. Constructors are special methods that initialize objects. Encapsulation hides implementation details and protects data using private attributes with public getters and setters. The Java source file layout follows a PIC order of package, import, classes. It also discusses creating JAR files to package related class files together.
chapter 5 concepts of object oriented programmingWondimuBantihun1
The document discusses the basic concepts of object-oriented programming in Java, including objects, classes, abstraction, encapsulation, inheritance, and polymorphism. It provides examples of objects versus classes, creating objects, access modifiers, constructors, encapsulation with getter and setter methods, single inheritance, abstract classes and interfaces for abstraction, and method overloading and overriding for polymorphism.
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
The lecture was condcuted by Tushar B Kute at YCMOU, Nashik through VLC orgnanized by MSBTE. The contents can be found in book "Core Java Programming - A Practical Approach' by Laxmi Publications.
This document introduces object-oriented programming concepts. It defines objects as having state, behavior, and identity. Classes are templates that define common attributes and behaviors of objects. Inheritance allows subclasses to extend and specialize parent classes. Access modifiers like public, protected, and private control visibility of class members.
This document discusses key concepts in Java including abstraction, encapsulation, inheritance, polymorphism, and interfaces. It defines these concepts and provides examples. Abstraction hides unnecessary details and shows essential information. Encapsulation wraps data and functions into a single unit. Inheritance allows a subclass to acquire properties of another class. Polymorphism supports method overloading and overriding. Interfaces can be used to implement inheritance between unrelated classes and specify what a class must do without defining how. The document also discusses access specifiers, modifiers, variables, literals, and static and final keywords.
Java uses an object-oriented approach where data and methods are bundled together as objects. A class defines the common attributes and behaviors of a group of objects. Individual objects are instantiated from classes and can interact by sending messages that invoke each other's methods. Encapsulation hides an object's internal data within itself and controls access via public methods.
Java uses an object-oriented approach where data and methods are bundled together as objects. A class defines the common attributes and behaviors of a group of objects. Individual objects are instantiated from classes and can interact by sending messages that invoke each other's methods. Encapsulation hides an object's internal data within itself and controls access via public methods.
The document provides information about object-oriented programming concepts in Java including objects, classes, constructors, and access modifiers. It defines an object as having state, behavior, and identity. A class is described as a template or blueprint for creating objects that share common properties. The document discusses default and parameterized constructors. It also covers the static keyword in relation to variables, methods, blocks, and nested classes. Other topics include finalizer methods, import statements, and the four levels of access control in Java.
This document discusses object-oriented programming concepts. It defines an object as anything that can be represented by data and manipulated by a program. An object has properties that hold its data values and methods that manipulate the properties. A class is a blueprint that defines the properties and methods for instances of objects. The document provides examples of physical and non-physical objects and how they are represented by properties and methods in object-oriented programming.
This document provides an introduction to object-oriented programming concepts like classes, objects, and methods in Java. It defines classes as templates that define attributes and behaviors of objects as variables and methods. Objects are instances of classes. The document explains how to declare a class with access modifiers, variables, constructors, and methods. It also demonstrates how to create objects using the new keyword and access object attributes and methods.
14 Years of Developing nCine - An Open Source 2D Game FrameworkAngelo Theodorou
A 14-year journey developing nCine, an open-source 2D game framework.
This talk covers its origins, the challenges of staying motivated over the long term, and the hurdles of open-sourcing a personal project while working in the game industry.
Along the way, it’s packed with juicy technical pills to whet the appetite of the most curious developers.
How the US Navy Approaches DevSecOps with Raise 2.0Anchore
Join us as Anchore's solutions architect reveals how the U.S. Navy successfully approaches the shift left philosophy to DevSecOps with the RAISE 2.0 Implementation Guide to support its Cyber Ready initiative. This session will showcase practical strategies for defense application teams to pivot from a time-intensive compliance checklist and mindset to continuous cyber-readiness with real-time visibility.
Learn how to break down organizational silos through RAISE 2.0 principles and build efficient, secure pipeline automation that produces the critical security artifacts needed for Authorization to Operate (ATO) approval across military environments.
Bonk coin airdrop_ Everything You Need to Know.pdfHerond Labs
The Bonk airdrop, one of the largest in Solana’s history, distributed 50% of its total supply to community members, significantly boosting its popularity and Solana’s network activity. Below is everything you need to know about the Bonk coin airdrop, including its history, eligibility, how to claim tokens, risks, and current status.
https://blog.herond.org/bonk-coin-airdrop/
Who will create the languages of the future?Jordi Cabot
Will future languages be created by language engineers?
Can you "vibe" a DSL?
In this talk, we will explore the changing landscape of language engineering and discuss how Artificial Intelligence and low-code/no-code techniques can play a role in this future by helping in the definition, use, execution, and testing of new languages. Even empowering non-tech users to create their own language infrastructure. Maybe without them even realizing.
In a tight labor market and tighter economy, PMOs and resource managers must ensure that every team member is focused on the highest-value work. This session explores how AI reshapes resource planning and empowers organizations to forecast capacity, prevent burnout, and balance workloads more effectively, even with shrinking teams.
Top 5 Task Management Software to Boost Productivity in 2025Orangescrum
In this blog, you’ll find a curated list of five powerful task management tools to watch in 2025. Each one is designed to help teams stay organized, improve collaboration, and consistently hit deadlines. We’ve included real-world use cases, key features, and data-driven insights to help you choose what fits your team best.
Integrating Survey123 and R&H Data Using FMESafe Software
West Virginia Department of Transportation (WVDOT) actively engages in several field data collection initiatives using Collector and Survey 123. A critical component for effective asset management and enhanced analytical capabilities is the integration of Geographic Information System (GIS) data with Linear Referencing System (LRS) data. Currently, RouteID and Measures are not captured in Survey 123. However, we can bridge this gap through FME Flow automation. When a survey is submitted through Survey 123 for ArcGIS Portal (10.8.1), it triggers FME Flow automation. This process uses a customized workbench that interacts with a modified version of Esri's Geometry to Measure API. The result is a JSON response that includes RouteID and Measures, which are then applied to the feature service record.
Revolutionize Your Insurance Workflow with Claims Management SoftwareInsurance Tech Services
Claims management software enhances efficiency, accuracy, and satisfaction by automating processes, reducing errors, and speeding up transparent claims handling—building trust and cutting costs. Explore More - https://www.damcogroup.com/insurance/claims-management-software
NTRODUCTION TO SOFTWARE TESTING
• Definition:
• Software testing is the process of evaluating and
verifying that a software application or system meets
specified requirements and functions correctly.
• Purpose:
• Identify defects and bugs in the software.
• Ensure the software meets quality standards.
• Validate that the software performs as intended in
various scenarios.
• Importance:
• Reduces risks associated with software failures.
• Improves user satisfaction and trust in the product.
• Enhances the overall reliability and performance of
the software
FME for Climate Data: Turning Big Data into Actionable InsightsSafe Software
Regional and local governments aim to provide essential services for stormwater management systems. However, rapid urbanization and the increasing impacts of climate change are putting growing pressure on these governments to identify stormwater needs and develop effective plans. To address these challenges, GHD developed an FME solution to process over 20 years of rainfall data from rain gauges and USGS radar datasets. This solution extracts, organizes, and analyzes Next Generation Weather Radar (NEXRAD) big data, validates it with other data sources, and produces Intensity Duration Frequency (IDF) curves and future climate projections tailored to local needs. This presentation will showcase how FME can be leveraged to manage big data and prioritize infrastructure investments.
In this session we cover the benefits of a migration to Cosmos DB, migration paths, common pain points and best practices. We share our firsthand experiences and customer stories. Adiom is the trusted partner for migration solutions that enable seamless online database migrations from MongoDB to Cosmos DB vCore, and DynamoDB to Cosmos DB for NoSQL.
A brief introduction to OpenTelemetry, with a practical example of auto-instrumenting a Java web application with the Grafana stack (Loki, Grafana, Tempo, and Mimir).
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...Alluxio, Inc.
Alluxio Webinar
June 10, 2025
For more Alluxio Events: https://www.alluxio.io/events/
Speaker:
David Zhu (Engineering Manager @ Alluxio)
Storing data as Parquet files on cloud object storage, such as AWS S3, has become prevalent not only for large-scale data lakes but also as lightweight feature stores for training and inference, or as document stores for Retrieval-Augmented Generation (RAG). However, querying petabyte-to-exabyte-scale data lakes directly from S3 remains notoriously slow, with latencies typically ranging from hundreds of milliseconds to several seconds.
In this webinar, David Zhu, Software Engineering Manager at Alluxio, will present the results of a joint collaboration between Alluxio and a leading SaaS and data infrastructure enterprise that explored leveraging Alluxio as a high-performance caching and acceleration layer atop AWS S3 for ultra-fast querying of Parquet files at PB scale.
David will share:
- How Alluxio delivers sub-millisecond Time-to-First-Byte (TTFB) for Parquet queries, comparable to S3 Express One Zone, without requiring specialized hardware, data format changes, or data migration from your existing data lake.
- The architecture that enables Alluxio’s throughput to scale linearly with cluster size, achieving one million queries per second on a modest 50-node deployment, surpassing S3 Express single-account throughput by 50x without latency degradation.
- Specifics on how Alluxio offloads partial Parquet read operations and reduces overhead, enabling direct, ultra-low-latency point queries in hundreds of microseconds and achieving a 1,000x performance gain over traditional S3 querying methods.
Key AI Technologies Used by Indian Artificial Intelligence CompaniesMypcot Infotech
Indian tech firms are rapidly adopting advanced tools like machine learning, natural language processing, and computer vision to drive innovation. These key AI technologies enable smarter automation, data analysis, and decision-making. Leading developments are shaping the future of digital transformation among top artificial intelligence companies in India.
For more information please visit here https://www.mypcot.com/artificial-intelligence
Providing Better Biodiversity Through Better DataSafe Software
This session explores how FME is transforming data workflows at Ireland’s National Biodiversity Data Centre (NBDC) by eliminating manual data manipulation, incorporating machine learning, and enhancing overall efficiency. Attendees will gain insight into how NBDC is using FME to document and understand internal processes, make decision-making fully transparent, and shine a light on underlying code to improve clarity and reduce silent failures.
The presentation will also outline NBDC’s future plans for FME, including empowering staff to access and query data independently, without relying on external consultants. It will also showcase ambitions to connect to new data sources, unlock the full potential of its valuable datasets, create living atlases, and place its valuable data directly into the hands of decision-makers across Ireland—ensuring that biodiversity is not only protected but actively enhanced.
AI and Deep Learning with NVIDIA TechnologiesSandeepKS52
Artificial intelligence and deep learning are transforming various fields by enabling machines to learn from data and make decisions. Understanding how to prepare data effectively is crucial, as it lays the foundation for training models that can recognize patterns and improve over time. Once models are trained, the focus shifts to deployment, where these intelligent systems are integrated into real-world applications, allowing them to perform tasks and provide insights based on new information. This exploration of AI encompasses the entire process from initial concepts to practical implementation, highlighting the importance of each stage in creating effective and reliable AI solutions.
2. What is OOP?
Object means a real-world entity
such as a pen, chair, table, computer,
watch, etc.
Object-Oriented Programming is a
methodology or paradigm to design
a program using classes and objects.
It simplifies software development
and maintenance by providing some
concepts:
Jurusan Teknik Informatika
Universitas Pendidikan Ganesha
3. What Is Class In OOP ?
• A class is a user defined data type that we can use
in our program, and it works as a blueprint for
creating objects but it doesn't actually provide any
real content itself
• The car class may specify that the color and model
are necessary for defining a car, but it will not
actually state what a specific car’s color or model is
• Classes enable the creation of specific instances of
the system being modeled (Object).
• Atributes and methods are basically variables and
functions that belongs to the class. There are often
referred to as class members
Jurusan Teknik Informatika
Universitas Pendidikan Ganesha
4. Example
For example, if you want to create a
class for students. In that case,
"Student" will be a class, and
student records
(like student1, student2, etc) will be
objects.
Jurusan Teknik Informatika
Universitas Pendidikan Ganesha
5. Properties of Java Classes
• A class does not take any byte of memory.
• A class is just like a real-world entity, but it is
not a real-world entity. It's a blueprint where
we specify the functionalities.
• A class contains mainly two things: Methods
and Data Members.
• A class can also be a nested class.
• Classes follow all of the rules of OOPs such as
inheritance, encapsulation, abstraction, etc.
Jurusan Teknik Informatika
Universitas Pendidikan Ganesha
6. Creating (Declaring)
a Java Class
• Run in terminal
touch Person.java
Jurusan Teknik Informatika
Universitas Pendidikan Ganesha
7. Types of Class
Variables
• Local variables − Variables defined inside
methods, constructors or blocks are called local
variables. The variable will be declared and
initialized within the method and the variable will
be destroyed when the method has completed.
• Instance variables − Instance variables are
variables within a class but outside any method.
These variables are initialized when the class is
instantiated. Instance variables can be accessed
from inside any method, constructor or blocks of
that particular class.
• Class variables − Class variables are variables
declared within a class, outside any method, with
the static keyword.
Jurusan Teknik Informatika
Universitas Pendidikan Ganesha
8. Important Points About Variables Scope
By default, a variable has default access. Default access modifier means we do not explicitly
declare an access modifier for a class, field, method, etc.
A variable or method declared without any access control modifier is available to any other
class in the same package. The fields in an interface are implicitly public static final and the
methods in an interface are by default public.
Java provides a number of access modifiers to
set access levels for classes, variables,
methods, and constructors. The four access
levels are −
default − Visible to the package. No modifiers are needed.
private − Visible to the class only.
public − Visible to the world.
protected − Visible to the package and all subclasses.
9. Classes: Instance Fields
• Instance variables are specific to each
instance of the class which means that
each object created from the class will
have its own copy of these variables. These
fields can be set in the following three
ways:
• If they are public, they can be set like
this instanceName.fieldName = someValue;
• They can be set by class methods.
• They can be set by the constructor method
(shown in the next exercise).
10. Method
• Methods are repeatable, modular
blocks of code used to accomplish
specific tasks. We have the ability
to define our own methods that
will take input, do something with
it, and return the kind of output
we want.
• Now, we’re going to learn how to
create object behavior using
methods.
Jurusan Teknik Informatika
Universitas Pendidikan Ganesha
11. Constructors
• Rules for Creating Java Constructors
• You must follow the below-given rules while creating Java constructors:
• The name of the constructors must be the same as the class name.
• Java constructors do not have a return type. Even do not use void as a return type.
• There can be multiple constructors in the same class, this concept is known as constructor
overloading.
• The access modifiers can be used with the constructors, use if you want to change the
visibility/accessibility of constructors.
• Java provides a default constructor that is invoked during the time of object creation. If you
create any type of constructor, the default constructor (provided by Java) is not invoked.
12. Constructor Method in
Java
• Java classes contain a constructor method
which is used to create instances of the
class.
• The constructor is named after the class. If
no constructor is defined, a default empty
constructor is used.
14. What are Java Objects?
An object is a variable of the type class, it is a basic component of an object-
oriented programming system. A class has the methods and data members
(attributes), these methods and data members are accessed through an object.
Thus, an object is an instance of a class.
Jurusan Teknik Informatika
Universitas Pendidikan Ganesha
15. Creating (Declaring) a Java Object
• Declaration − A variable declaration with a variable name with an
object type.
• Instantiation − The 'new' keyword is used to create the object.
• Initialization − The 'new' keyword is followed by a call to a
constructor. This call initializes the new object.
Jurusan Teknik Informatika
Universitas Pendidikan Ganesha
16. Accessing Instance
Variables and
Methods
• Instance variables and methods are accessed
via created objects. To access an instance
variable, following is the fully qualified path −
Jurusan Teknik Informatika
Universitas Pendidikan Ganesha
17. Java instance
Example
• Java instances are objects that are based
on classes. For example, Bob may be an
instance of the class Person.
• Every instance has access to its own set
of variables which are known as instance
fields, which are variables declared
within the scope of the instance. Values
for instance fields are assigned within
the constructor method.
18. Rules for using the Classes
and Objects Concepts
• There can be only one public class per source file.
• A source file can have multiple non-public classes.
• The public class name should be the name of the source file as well which should be appended
by .java at the end. For example − the class name is public class Employee{} then the source file should
be as Employee.java.
• If the class is defined inside a package, then the package statement should be the first statement in the
source file.
• If import statements are present, then they must be written between the package statement and the
class declaration. If there are no package statements, then the import statement should be the first line
in the source file.
• Import and package statements will imply to all the classes present in the source file. It is not possible
to declare different import and/or package statements to different classes in the source file.
• Classes have several access levels and there are different types of classes;
abstract classes, final classes, etc. We will be explaining about all these in the
access modifiers chapter.
Jurusan Teknik Informatika
Universitas Pendidikan Ganesha
19. Access Modifiers
• Java access modifiers are used to specify the scope of the
variables, data members, methods, classes, or constructors.
These help to restrict and secure the access (or, level of access)
of the data.
Default (No
keyword
required)
Private Protected Public
Jurusan Teknik Informatika
Universitas Pendidikan Ganesha
20. Default Access Modifier
• Default access modifier means we
do not explicitly declare an access
modifier for a class, field, method,
etc.
• A variable or method declared
without any access control
modifier is available to any other
class in the same package. The
fields in an interface are implicitly
public static final and the methods
in an interface are by default
public.
Jurusan Teknik Informatika
Universitas Pendidikan Ganesha
21. Private Access Modifier
• Methods, variables, and constructors
that are declared private can only be
accessed within the declared class
itself.
• Using the private modifier is the main
way that an object encapsulates
itself and hides data from the outside
world.
• Using the private modifier is the
main way that an object
encapsulates itself and hides
data from the outside world.
Jurusan Teknik Informatika
Universitas Pendidikan Ganesha
22. Protected Access
Modifier
• Variables, methods, and constructors,
which are declared protected in a
superclass can be accessed only by the
subclasses in other package or any
class within the package of the
protected members' class.
• The protected access modifier cannot
be applied to class and interfaces.
Methods, fields can be declared
protected, however methods and fields
in a interface cannot be declared
protected.
• Protected access gives the subclass a
chance to use the helper method or
variable, while preventing a nonrelated
class from trying to use it.
23. Public Access Modifier
• A class, method, constructor,
interface, etc. declared public can be
accessed from any other class.
Therefore, fields, methods, blocks
declared inside a public class can be
accessed from any class belonging to
the Java Universe.
• However, if the public class we are
trying to access is in a different
package, then the public class still
needs to be imported. Because of
class inheritance, all public methods
and variables of a class are inherited
by its subclasses.
Jurusan Teknik Informatika
Universitas Pendidikan Ganesha
24. Access
Modifiers and
Inheritance
• Methods declared public in a superclass also must be public in
all subclasses.
• Methods declared protected in a superclass must either be
protected or public in subclasses; they cannot be private.
• Methods declared private are not inherited at all, so there is no
rule for them.
Jurusan Teknik Informatika
Universitas Pendidikan Ganesha