opp aat 2 (24951A6605)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

5.

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.

6. Polymorphism: Polymorphism enables objects of different classes to be treated


as objects of a common superclass. This provides flexibility and extensibility in code
design

7. Flexibility: OOP makes it easier to adapt to changes and evolving requirements.


Modifications can often be made within specific classes without affecting the
entire system.

8. Code Organization: OOP provides a structured way to represent real-world


entities and their interactions. This aids in the modelling and design of software
systems.

9. Ease of Collaboration: OOP facilitates collaboration among developers since they


can work on different classes or objects simultaneously. It promotes teamwork and
code sharing.

Disadvantages of Object- acquainted Programming( OOP)

1. Complexity OOP is complex, especially in large systems, where managing a


heritage of classes and objects can come grueling .
2. Steep Learning wind literacy and applying OOP generalities can be challenging
for newcomers. It frequently requires a shift in allowing compared to procedural
programming.
3. Performance Outflow OOP may introduce performance above due to the
circular access to data and styles through objects and classes. In some cases,
this can impact prosecution speed.
4. Memory operation Objects consume memory, and for operations that produce
a large number of objects, memory operation can come a concern.
5. Inefficient for Small Programs OOP might be overabundance for small programs
with limited complexity. The fresh structure and outflow may not be justified.
6. Implicit forOver-Engineering. In some cases, OOP can lead to over- engineering,
where inventors produce exorbitantly complex class scales that are delicate to
manage.
7. delicate Debugging Debugging can be more complex in OOP, particularly when
dealing with complex heritage scales or polymorphic geste
.
8. Lack of Universality OOP is n't always the stylish fit for every problem or
operation. Some problems may be more suited to other programming
paradigms, similar as procedural or functional programming..
3.Discuss about public access modifier with program
Public Access Modifier

In object-oriented programming, access modifiers define the scope and visibility of


classes, methods, and variables. The public access modifier is the least restrictive,
granting the widest scope of accessibility.

Key Characteristics of Public Access Modifier:

• Accessibility: Public members can be accessed from anywhere within the


program, regardless of package or class boundaries.

• Scope: The scope of a public member extends to the entire program.

• Usage: Public members are typically used for class interfaces, API components,
or elements that need to be accessed by other classes.

public class PublicMod {

public int publicVar;

public void publicMet() {

System.out.println("This is a public method.");

public class AnotherClass {

public static void main(String[] args) {

PublicMod obj = new PublicMod ();

System.out.println(obj.publicVariable);

obj.publicMethod();

When to Use Public Access Modifier:

• 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.

Cautions When Using Public Access Modifier:

• 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.

4.Draw a class diagram for Library Management System


Classes of Library Management System : • Library Management System class – It
manages all operations of Library Management System. It is central part of organization
for which software is being designed.

• User Class – It manages all operations of user.

• Librarian Class – It manages all operations of Librarian.

• Book Class – It manages all operations of books. It is basic building block of system.

• Account Class – It manages all operations of account.

• Library database Class – It manages all operations of library database.

• Staff Class – It manages all operations of staff.

• Student Class – It manages all operations of student.

Attributes of Library Management System :

• Library Management System Attributes – UserType, Username, Password

• User Attributes – Name, Id

• Librarian Attributes – Name, Id, Password, SearchString

• Book Attributes – Title, Author, ISBN, Publication

• Account Attributes – no_borrowed_books, no_reserved_books, no_returned_books,


no_lost_books fine_amoun

t • Library database Attributes – List_of_books

• Staff Class Attributes – Dept

• Student Class Attributes – Class


Methods of Library Management System :
• Library Management System Methods – Login(), Register(), Logout()

• User Methods – Verify(), CheckAccount(), get_book_info()

• Librarian Methods – Verify_librarian(), Search()

• Book Methods – Show_duedt(), Reservation_status(), Feedback(), Book_request(),


Renew_info()

• Account Methods – Calculate_fine()

• Library database Methods – Add(), Delete(), Update(), Display(), Search()


5.What is constructor? Explain the concept of default and
default copy with suitable example.

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).

public class Officer {

String name;

int age;

public Offiicer() {

// ... other methods

The default constructor is called, and the name and age variables are initialized to null
and 0, respectively. By:

Officer officer1= new Officer ();

Default Copy Constructor :

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.

public class Officer{

String name;

int age;

public Officer(Officer other) {

this.name = other.name;

this.age = other.age;

// ... other methods

In this example, when you create a new Person object using an existing one:

Officer officer1= new Officer("Alice", 30);

Officer officer2= new Officer(person1);

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.

6.Write short notes on a) Early binding, b) late binding

Early Binding

• Definition: The process of resolving function calls and variable references at


compile time.

• Mechanism: The compiler determines the exact function or variable to be used


based on the static type of the object.

• Advantages:

o Faster execution due to no runtime lookup.

o Enhanced type checking and error detection at compile time.

• Disadvantages:
o Less flexibility as the binding is fixed at compile time.

o Limited to static polymorphism.

o class Parentclass {

o void show() {

o System.out.println("Parent class meth");

o }

o }

o class Child extends Parent {

o void show() {

o System.out.println("Child class method");

o }

o public static void main(String[] args) {

o Parent obj1 = new Parent();

o obj1.show();

o Child obj2 = new Child();

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

• Definition: The process of resolving function calls and variable references at


runtime.

• Mechanism: The virtual function mechanism allows the appropriate function to


be determined based on the dynamic type of the object.

• Advantages:

o Greater flexibility as the binding can change at runtime.

o Supports dynamic polymorphism and runtime method resolution.


• Disadvantages:

o Slower execution due to the runtime lookup.

o Potential for runtime errors if the required function is not found.

Sources and related content

class Parent {

void show() {

System.out.println("Parent class method");

class Child extends Parent {

void show() {

System.out.println("Child class method");

public static void main(String[] args) {

Parent obj1 = new Child();

obj1.show(); // Output: Child class method

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.

7.How is an abstract class different from an interface?


An abstract class and an interface are both constructors in object-oriented
programming

that provide a way to achieve abstraction, but they have some key differences:

Keyword:

• Declared using the ‘abstract’ keyword.


default
and
static methods.

• Key Points:

9.What is a file structure in operating systems?


In operating systems, a train structure refers to the association and layout of data

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

directories on a computer's storehouse.


1. Directory( Folder)

• A directory is a vessel that holds lines and other directories. It provides

a inherited association for lines, allowing them to be organized into

a logical structure.

2. Path

• A path is a unique identifier that specifies the position of a train or

directory within the train structure. It includes the directory scale

leading to the train.

3. train System

• The train system is responsible for managing lines and directories on a

storehouse device. It defines the rules for naming lines, organizing

directories, and managing access warrants.

4. Attributes

• Each train or directory in a train structure has associated attributes similar as

name, size, create date, revise date, and warrants. These

attributes give information about the train or directory.

Types of train Structures


1. Flat train Structure

• All lines are stored in a single directory without any subdirectory. This

structure is simple but can come ungovernable as the number of lines

increases.

2. Hierarchical train Structure

• lines are organized in a tree-like structure with a single root directory.

Each directory can contain lines and subdirectories, creating a hierarchy.


10.Write short notes on: a) Manipulators, b) protected
access specifier
a) Manipulators in Java:
In Java, "manipulators" are not normally used in the sense of input/output streams
as they have in languages like C++. Formatting is usually done through the Formatter
class or methods, like String.format() or System.out.printf().
Use of 'System.out.printf()';
public class ManipulatorsExample {
public static void main(String[] args) {
int num = 42;
System.out.printf("Formatted number: %d%n", num);
}}
In this example, %d is a format specifier that represents an integer, and %n
represents the platform-specific newline character.
b) Protected Access Specifier in Java:
The protected access specifier is one of the four access modifiers that are used to
control the visibility and accessibility of class members (fields, methods) within a
class.
hierarchy. The other access specifiers are public, private, and the default (package-
private).
Usage of 'protected' Access Specifier:
public class Base {
protected int protectedVar;
protected void protected_Method() {
}
}
public class Derived extends Base{
public void accessProtected_Member() {
protected_Var = 42;
}
}
Key features about the protected access modifier in Java:
1. Class Level and Sub-Class: A member declared as a protected is accessible
within the same class where it has been defined and
by all subclass(s) that are inherited by such a class.
2. Not Accessible Outside the Class Hierarchy:
• The protected members are not accessible directly from outside the class
hierarchy, just like in other languages.
3. Encapsulation and Subclass Extension:
• The protected access specifier supports encapsulation and allows derived classes
to access and extend the behavior of the base class without exposing
implementation details.

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.

You might also like