Chapter 1 Java
Chapter 1 Java
5 Marks
1. What are the basic concepts of OOPs? Explain.
a) Object
Any entity that has state and behavior is known as an object. For
example, a chair, pen, table, bike, etc. It can be physical or logical.
An Object can be defined as an instance of a class. An object contains an
address and takes up some space in memory. Objects can communicate
without knowing the details of each other's data or code.
b) Class
Collection of objects is called class. It is a logical entity.
A class can also be defined as a blueprint from which you can create an
individual object. Class doesn't consume any space.
c) Inheritance
inheritance is a fundamental concept in object-oriented programming
(OOP) that allows one class (subclass or derived class) to inherit
attributes and methods from another class (superclass or base class).
This promotes code reuse and enables hierarchical classification of
classes.
d) Polymorphism
If one task is performed in different ways, it is known as polymorphism.
For example: to convince the customer differently, to draw something,
for example, shape, triangle, rectangle, etc.
In Java, we use method overloading and method overriding to achieve
polymorphism.
e) Abstraction
Java is a fundamental concept in object-oriented programming (OOP)
that focuses on hiding the implementation details of methods and
providing only the functionality that is necessary for the user. It allows
developers to create a simplified model of a complex system,
emphasizing what an object does rather than how it does it.
f) Encapsulation
Binding (or wrapping) code and data together into a single unit are
known as encapsulation. For example, a capsule, it is wrapped with
different medicines.
2. Explain features of java.
https://www.javatpoint.com/features-of-java
3. What is Encapsulation? Explain with example.
Encapsulation in Java is a fundamental principle of object-oriented
programming (OOP) that involves bundling the data (attributes) and
methods (functions) that operate on the data into a single unit (class). It
allows the attributes of a class to be hidden from other classes, ensuring
that they can only be accessed and modified through defined methods.
Encapsulation provides several benefits such as improved code
organization, reusability, and security.
4. Basic structure of java program.
https://i.postimg.cc/wMHxfKv1/structure.png
5. Explain decision making statements with syntax and example.
https://chatgpt.com/share/70daef51-2040-4c9a-864d-59fe7c9d821e
10 Marks
1) Explain type casting and type conversion with example
1. Type Casting
Type casting is the process of converting a variable from one data type
to another. In Java, there are two types of casting:
Implicit Casting (Widening Casting): Automatically done by the
compiler when converting a smaller type to a larger type size.
Explicit Casting (Narrowing Casting): Manually done by the
programmer when converting a larger type to a smaller size type.
// Modulus
int remainder = a % b;
System.out.println("Remainder (a % b): " + remainder);