0% found this document useful (0 votes)
36 views5 pages

Java Arrays, Strings, and Inheritance Guide

Uploaded by

powerprabhas0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views5 pages

Java Arrays, Strings, and Inheritance Guide

Uploaded by

powerprabhas0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

MODULE-III: ARRAYS, STRINGS AND INHERITANCE

2M Questions
1. Explain the difference between a 1D array and a multidimensional array in Java.
2. Explain what an irregular array is in Java.
3. Give the purpose of the length() method in the String class with an example
4. List any two differences between Vector and ArrayList Classes
5. What is a string literal in Java? Give one example and how are string literals stored in
memory?
6. What will be the output of:
class Main {
public static void main(String[] args) {
[Link]("Hello" + 5 + 10);
}
}
7. Write a Java statement to join “ JAVA” and “PROGRAMMING” using [Link]()
method using specified delimiter “ ’’ (space).
8. Write a Java statement to reverse the contents of a String Buffer class object named
“sb”.
9. Explain the use of the “super” keyword in Java inheritance.
10. List the uses of the final keyword in Java.

5M Questions
1. Explain the concept of irregular arrays in Java with an example.
2. Describe the features of the Vector class in Java and Write a Java program to
demonstrate the use of the following methods by creating a vector element
 To Add an Element
 To insert an Element
 To remove an Element
3. What is an ArrayList in Java? Explain how it differs from an array.
Write a Java program to by creating an ArrayList of Elements:
 Create an ArrayList of integers,
 Add five elements,
 Remove one element
4. (a) Describe the constructors of the String class
(b) Describe the methods of StringBuffer class such as
append(),ensureCapacity(),reverse() and insert().
5. Explain the concept of inheritance in [Link] its advantages and write a Java
program to demonstrate single inheritance (a subclass inheriting from one superclass).
6. Differentiate between single, multilevel, and hierarchical inheritance with the help of
suitable diagrams and examples.
7. Analyze how constructors are executed in a multilevel inheritance hierarchy.
8. Illustrate a program with an example showing method overriding and runtime
polymorphism.
9. Write a Java program to demonstrate how an abstract class can contain both abstract
and non-abstract methods.
10. Write a Java program to demonstrate the behavior of the final keyword when:
 A variable is declared final,
 A method is declared final, and
 A class is declared final.

8M Questions

1. A company stores the monthly sales of 12 months in a 1D array. Write a Java


program to:
 Accept sales data for 12 months
 Calculate and display the total and average sales,
 Find and display the month with the highest and lowest sales,
 Display all sales values above the average. Also, Use loops and conditional
statements to process the array.
2. Explain the concept of arrays of varying lengths and arrays as vectors with examples.
3. (a) Explain how string comparison and searching operations are performed in Java
using methods like equals(), compareTo(), and indexOf().
(b) Write a Java program to demonstrate string modification and data conversion
(e.g., converting an integer to a string and vice versa).
4. A software company is developing a text processing tool that needs to handle both
static text (using String) and editable text (using StringBuffer). Write a Java program
to:
 Create strings using different String constructors, such as:
 From a string literal
 From a character array
 From a byte array
 Display each string created and explain how the constructor works.
 Create a StringBuffer object using both the default constructor and a
parameterized constructor with an initial string.
 Perform the following operations on the StringBuffer:
 Append text
 Insert a word
 Replace a portion of text
 Reverse the content
 Display the final modified string and its capacity. Also, explain why
StringBuffer is preferred over String for text modifications.
5. Suppose a class BankAccount contains protected members balance and
accountNumber. The class also has a method displayAccountDetails() that displays
these details. A subclass SavingsAccount extends BankAccount and adds a private
member interestRate.

Task:
Write a Java program to demonstrate the following:
 How a subclass can access the protected members of its superclass.
 How to define a method in the subclass that accesses the protected members of
the superclass.
 Explain, with proper comments, why direct access to protected members from
the subclass is allowed, but from outside classes it is not.
6. Explain constructor execution hierarchy in multilevel inheritance and Single
Inheritance with two different suitable example programs.
7. Discuss method overriding in Java and Describe the concept of superclass references
and subclass objects. How can a superclass reference variable refer to a subclass
object.
8. Write a Java program to create an abstract class Animal with an abstract method
sound(). Create subclasses Dog and Cat that extend Animal and provide
implementations for the sound() method printing appropriate sounds for each animal.
Demonstrate the use of these classes in a main method by creating objects of Dog
and Cat. Explain why the Animal class cannot be instantiated directly.
9. Consider a class Parent with an instance variable num and a method display() that
prints the value of num. The subclass Child also has an instance variable num and
overrides the display() method. Write a Java program to demonstrate:
i. How to use the super keyword to access the parent class variable num
inside the subclass.
ii. How to call the parent class method display() from the overridden
method in the subclass using the super keyword.
iii. How to invoke the parent class constructor from the subclass
constructor using super().
10. Design a Java class hierarchy showing the use of the final keyword with
variables, methods, and classes. Discuss how the final affects inheritance and
method overriding.
MODULE-IV: INTERFACES AND PACKAGES
2M Questions

1. What is an interface in Java.


2. How does multiple inheritance differ from single inheritance in Java.
3. What keyword is used to implement an interface in Java.
4. Can an interface extend another interface? Give an example.
5. What is a nested interface.
6. What is the purpose of the package keyword in Java.
7. How do you import a user-defined package in a Java program.
8. What is the difference between import and static import.
9. Mention any two advantages of using packages in Java.
10. What is the significance of the File class in Java I/O.

5M Questions

1. Explain the steps to create and implement an interface in Java with an example.
2. Write a Java program that implements multiple interfaces in a single class.
3. Differentiate between class inheritance and interface inheritance in Java.
4. What are nested interfaces? Explain with an example.
5. Describe the access control levels in packages with respect to member access.
6. Explain the use of the import statement with suitable examples.
7. Discuss the role of static import in Java. Give an example to illustrate its use.
8. What are the advantages of using packages in Java application development?
9. Write a short note on the fundamentals of file handling in Java.
10. Explain the difference between byte stream and character stream classes in Java I/O.

8M Questions

1. Discuss in detail the concept of interfaces in Java. How do interfaces support multiple
inheritance? Illustrate with a program.
2. Explain how multiple and nested inheritance are implemented using interfaces in
Java. Provide suitable examples.
3. Write a Java program demonstrating the creation of interfaces, their implementation
by classes, and accessing them via interface references.
4. How can multiple interfaces be implemented by a single class? Write a Java program
to show this concept.
5. Describe how interfaces can be extended in Java. Write a program to demonstrate
extending an interface.
6. Explain the concept of nested interfaces in detail. Write a Java program that defines
and implements a nested interface.
7. Discuss in detail the concept and structure of packages in Java. How do packages
promote modular programming?
8. Explain member access control in Java packages. Use examples to illustrate public,
protected, default, and private access levels.
9. Write a Java program that demonstrates importing user-defined packages and using
static import.
10. Describe the fundamentals of Java File I/O. Write a program to read from and write to
a text file using character streams.
MODULE-V: EXCEPTION HANDLING AND CONCURRENCY

2M Questions

1. What happens when an exception is not caught in Java. Explain with a short example.
2. Differentiate between checked and unchecked exceptions with examples.
3. What is the purpose of the `finally` block. Give a real-life analogy.
4. Define `throw` and `throws` keywords in Java with syntax.
5. In a banking system, a user enters 0 as the withdrawal amount. Which type of exception could
you use to handle this case.
6. What is the significance of the `start()` method in multithreading.
7. Define an inner class. How is it useful in modular design.
8. What is a lambda expression and how does it simplify event handling in Java.

5M Questions
1. Explain the hierarchy of exceptions in Java with a neat diagram.
2. A user inputs a character instead of a number in a program. Write a code snippet using try-
catch to handle the situation.
3. How does the `finally` block ensure resource management in file-handling operations?
Illustrate with a scenario.
4. Write a program using multiple catch blocks to handle both `ArithmeticException` and
`ArrayIndexOutOfBoundsException` for a simple calculator program.
5. In an online voting system, throw a custom exception `NotEligibleException` when the user’s
age is below 18.
6. Compare the two ways of creating threads in Java with examples. Which approach is
preferable in real-world applications.
7. Write a Java program using an inner class to access the outer class’s variable and display its
value.
8. Explain how lambda expressions improve code readability in Java. Use a practical example of
a greeting message.

8M Questions
1. Design a program that demonstrates nested try-catch blocks where division and array
operations are performed together. Explain the flow of execution.
2. Discuss the consequences of an uncaught exception with a case study scenario.
3. Develop a custom exception `InvalidInputException` that is thrown when a user
enters negative marks in a student grading system.
4. Explain the working of rethrowing exceptions in nested try-catch structures with code
and output trace.
5. Create a multithreaded Java program that simulates two threads running
simultaneously: one printing numbers and another printing characters.
6. Write a program that demonstrates the use of finally block in a file operation (open,
read, close). Discuss its significance when exceptions occur.
7. Explain how lambda expressions can be used to implement a Runnable interface for
concurrent tasks. Provide code and output explanation.
8. Consider a software module where you need to validate user credentials and perform
data upload concurrently. Design the logic using exception handling and
multithreading concepts together.

You might also like