opp aat 2 (24951A6605)
opp aat 2 (24951A6605)
opp aat 2 (24951A6605)
Inheritance: Inheritance allows for the creation of new classes (subclasses) that
inherit attributes and methods from existing classes (superclasses). This promotes
code reuse and supports the "is-a" relationship between objects.
• Usage: Public members are typically used for class interfaces, API components,
or elements that need to be accessed by other classes.
System.out.println(obj.publicVariable);
obj.publicMethod();
• Class Interfaces: Public classes often define the public interface of a library or
framework.
• API Components: Public methods and classes are frequently used to expose
functionality to other parts of the program or to external applications.
• Shared Data: Public variables (though less common) can be used to share data
between different parts of the program.
• Overuse: Overusing the public access modifier can lead to less encapsulated
designs, making code more prone to errors and harder to maintain.
• Security Risks: Exposing too many public members can increase security risks,
especially in larger applications.
• Book Class – It manages all operations of books. It is basic building block of system.
Constructor :
A constructor is a special type of system in object- acquainted programming that's
automatically called when an object of a class is created. It's primarily used to initialize
the object's state, setting original values to its case variables.
Default Constructor :
A default constructor is a constructor that does not take any arguments. It's
automatically handed by the compiler if you do not explicitly define any constructors in
your class. This dereliction constructor initializes the case variables to their dereliction
values( e.g., 0 for figures, null for references).
String name;
int age;
public Offiicer() {
The default constructor is called, and the name and age variables are initialized to null
and 0, respectively. By:
A Default copy constructor is a special type of constructor that creates a new object as
a dupe of an living object. It's also automatically handed by the compiler if you do not
define any other constructors. still, this dereliction dupe constructor performs a
shallow dupe, which means it clones references to the objects, not the objects
themselves.
String name;
int age;
this.name = other.name;
this.age = other.age;
In this example, when you create a new Person object using an existing one:
The default copy constructor is called, and Officer2 becomes a shallow dupe of
Officer2. This means that both objects , the same name string. Any changes made to
Officer2.name will also affect person2.name.
To perform a deep copy, you need to create a new object for each instance variable and
copy the values individually.
Early Binding
• Advantages:
• Disadvantages:
o Less flexibility as the binding is fixed at compile time.
o class Parentclass {
o void show() {
o }
o }
o void show() {
o }
o obj1.show();
o obj2.show();
o }
o }
• In this example, the compiler determines the method to call based on the static type of
the object. For obj1, it's Parent, so the Parent class's show() method is called. For
obj2, it's Child, so the Child class's show() method is called.
o
Late Binding
• Advantages:
class Parent {
void show() {
void show() {
Here, the show() method in the Parent class is declared as virtual. This enables late
binding. When obj1.show() is called, the compiler doesn't know the exact type of the
object at compile time. It's only at runtime that the JVM determines that obj1 actually
refers to a Child object. Hence, the Child class's show() method is called.
that provide a way to achieve abstraction, but they have some key differences:
Keyword:
• Key Points:
•
within lines. It defines how data is stored, inserted, associated on storehouse bias
similar as hard drives, solid- state drives, or other storehouse media. The train
structure is a
critical aspect of train systems, which are responsible for lines and
a logical structure.
2. Path
3. train System
4. Attributes
• All lines are stored in a single directory without any subdirectory. This
increases.
Note :While Java does n't use the term" manipulators" in the same way as C, the
principles of formatting and access control are still applicable. Java emphasizes the use
of styles and classes for formatting and the access modifiers( public, private,
defended, and dereliction) for controlling access to class members.