CHAPTER 13
Beginner
Classes and Objects
Updated: May 17, 2026
5 min read
# CHAPTER 13
Classes and Objects
1. Introduction
Classes and objects are the fundamental building blocks of Java. A class defines the structure; an object brings it to life. In this chapter, we'll build real-world classes with attributes, methods, and access control.2. Learning Objectives
- Create classes with attributes and methods.
-
Instantiate objects using
new.
-
Use access modifiers (
public,private,protected, default).
-
Understand
staticvs instance members.
-
Use the
thiskeyword.
3. Creating a Class
java
4. Creating Objects
java
5. Access Modifiers
| Modifier | Class | Package | Subclass | World |
|---|---|---|---|---|
public | ✅ | ✅ | ✅ | ✅ |
protected | ✅ | ✅ | ✅ | ❌ |
| (default) | ✅ | ✅ | ❌ | ❌ |
private | ✅ | ❌ | ❌ | ❌ |
6. The this Keyword
Refers to the current object instance.
java
7. Static vs Instance Members
java
- Static: Belongs to the class. One copy shared.
- Instance: Belongs to each object. Each has its own copy.
8. Mini Project: Employee Management System
java
9. MCQ Quiz with Answers
Question 1
Which keyword creates an object?
Question 2
private fields are accessible from:
Question 3
this refers to:
Question 4
Static variables are shared by:
Question 5
Default access modifier allows access from:
Question 6
Object references are stored on:
Question 7
Object data is stored on:
Question 8
How many public classes can a .java file have?
Question 9
Static methods can access:
Question 10
this() calls:
10. Interview Questions
- Q: What is the difference between a class and an object?
- Q: Explain the difference between static and instance variables.
-
Q: Why is
thiskeyword needed?
- Q: Can a static method access instance variables? Why or why not?
11. Summary
Classes define the blueprint with attributes and methods. Objects are instances created withnew. Access modifiers control visibility. static members belong to the class; instance members belong to each object. The this keyword resolves ambiguity between fields and parameters.