0% found this document useful (0 votes)
2 views1 page

Assignment - 2

The document contains a series of theory and program questions related to Java programming concepts. Key topics include the String class, method overloading, inheritance types, constructors, access modifiers, and polymorphism. Additionally, it provides programming tasks to demonstrate these concepts through practical examples.

Uploaded by

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

Assignment - 2

The document contains a series of theory and program questions related to Java programming concepts. Key topics include the String class, method overloading, inheritance types, constructors, access modifiers, and polymorphism. Additionally, it provides programming tasks to demonstrate these concepts through practical examples.

Uploaded by

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

Theory Questions

1. Explain the features of the `String` class in Java. How is it different from `StringBuffer`?
2. Discuss any five commonly used methods of the String class in Java with syntax and
examples.
3. What is method overloading? Explain with examples. How is it related to compile-time
polymorphism?
4. What are the different types of inheritance in Java? Explain with examples and diagrams.
5. Describe the role of constructors in Java. What are the different types of constructors?
6. Write notes on access modifiers in Java. Include a comparison table of private, public,
protected, and default.
7. Explain the use of the `this` keyword in Java with suitable examples.
8. Differentiate between static and non-static members. Give use cases of static variables
and methods.
9. Define method overriding. How does it support run-time polymorphism in Java?
10. Write a note on `final` keyword in Java. Explain its use at variable, method, and class
levels with examples.
Program Questions
1. Write a Java program to demonstrate the use of different `String` methods like `length()`,
`charAt()`, `indexOf()`, and `substring()`.
2. Create a Java program to implement method overloading for calculating the area of a
rectangle and a circle.
3. Write a Java program demonstrating single inheritance using an `Animal` base class and
`Dog` derived class.
4. Write a Java program to demonstrate multilevel inheritance using `Animal`, `Mammal`,
and `Dog` classes.
5. Write a Java program to demonstrate the use of `this` keyword to resolve ambiguity
between instance variables and parameters.
6. Create a Java class to define a constructor and initialize object members using a
parameterized constructor and non-parameterized constructor.
7. Write a Java program with nested methods that calculates the square and cube of a
number.
8. Demonstrate method overriding using a superclass `Vehicle` and a subclass `Car`. Show
how dynamic dispatch works.
9. Write a Java program to implement polymorphism by creating a superclass Shape and
subclasses Circle, Rectangle, and Triangle with overridden area() methods.
10. Write a Java program to demonstrate method overloading by creating a class Calculator
with multiple versions of the method add():
add(int a, int b) – adds two integers
add(double a, double b) – adds two doubles
add(int a, int b, int c) – adds three integers
Create an object of Calculator in the main() method and call all overloaded methods.

You might also like