Advanced Java Programming · Unit 1
Object-Oriented Programming Fundamentals
Exam-focused notes for Object-Oriented Programming Fundamentals (Advanced Java Programming, BIT401): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.
What this unit covers
- Method overloading and overriding
- Inheritance and class hierarchies
- Interface design and implementation
- Abstract classes and polymorphism
- Constructor chaining
- Inner classes and anonymous inner classes
- Package definition and organization
- Final keyword and immutability
- Object class and its methods
Inner classes and anonymous inner classes
How do you create inner class and anonymous inner class? Create a class EMPLOYEE with data members Emp_ID, Name and Occupation, and write those objects to the file DOC.DAT whose occupations is doctor.[10]
An inner class is a class defined within another class. It has access to the outer class's members. Syntax: Creating objects: An anonymous inner class is a class without a name, typically used to override methods of an interface or abstract class on-the-fly...
Full solved answer →Package definition and organization
Define package. What is the use of final keyword and finally block? [5]
A package is a namespace mechanism in Java used to organize and group related classes, interfaces, and sub-packages into a hierarchical structure. Packages help avoid naming conflicts and provide a way to control access to classes and members. Example struc...
Full solved answer →Interface design and implementation
Why do we need interface? Define an interface named shape with area ( ) method. Create a class named Rectangle with length and breadth circle with radius that implements shape interface. Now create the object of both classes and display their area.[10]
Interfaces are needed for the following reasons: 1. Abstraction: Interfaces define a contract that specifies what methods a class must implement, without specifying how they should be implemented. 2. Polymorphism: Interfaces allow objects of different class...
Full solved answer →Constructor chaining
Describe the chain of constructor with example. [5]
Constructor chaining is a technique in object-oriented programming where one constructor calls another constructor of the same class or parent class. This allows code reuse and initialization of objects in a flexible manner. One constructor calls another co...
Full solved answer →Final keyword and immutability
Write short notes on a. Final keyword b. Object class [5]
The final keyword in Java is a modifier used to restrict modification. It can be applied in three contexts: 1. Final Variables: - Once assigned, the value cannot be changed - Must be initialized when declared or in the constructor - Example: 2. Final Method...
Full solved answer →Method overloading and overriding
Discuss the concept of method overriding. Write a program to create Person class with variables id, and name. Include methods getPerson() and showPerson() in the class. Again, create another class named Employee, which is child of person class. Include member variable salary, and methods getEmployee(), and showEmployee() in the class. Again, create a third class named Typist, which is child of Employee. Include variable typespeed, and methods getTypist(), and showTypist() in the class. Finally, create two objects of Typist class and read and display their details.[10]
Method Overriding is a feature of Object-Oriented Programming that allows a child class to provide a specific implementation of a method that is already defined in its parent class. When a method in a child class has the same name, return type, and paramete...
Full solved answer →What is method overloading? Explain with example. [5]
Method overloading is a feature of Object-Oriented Programming that allows a class to have multiple methods with the same name but different parameters. It is a way to implement compile-time (static) polymorphism. The methods must differ in: - Number of par...
Full solved answer →Make Unit 1 stick
Practice BIT401 with flashcards & quizzes