[Go to site: main page, start]

0% found this document useful (0 votes)
5 views2 pages

Java Practical Programming Exercises

The document presents a series of practical Java programming questions and tasks. These include writing programs for factorial calculation, string manipulation, interface implementation, class inheritance, exception handling, and method overloading. Each task is aimed at reinforcing fundamental Java concepts and object-oriented programming principles.
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)
5 views2 pages

Java Practical Programming Exercises

The document presents a series of practical Java programming questions and tasks. These include writing programs for factorial calculation, string manipulation, interface implementation, class inheritance, exception handling, and method overloading. Each task is aimed at reinforcing fundamental Java concepts and object-oriented programming principles.
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

JAVA PRACTICAL QUESTIONS

[Link] program to print the factorial of a number.


[Link] a Java program to compare two strings using equals()
and equalsIgnoreCase().
[Link] a Java program to replace all occurrences of 'a' with
'o' in a given string using replace() method.(apple is fav fruit)
4. Write a Java program that creates a StringBuffer object,
appends multiple strings using the append() method, and
prints the final result.
5. Create two interfaces, Flyable and Swimmable, with
methods fly() and swim(). Implement both interfaces in a
class called Duck.
6. Create an interface Vehicle with a method speedUp().
Implement this interface in Car and Bike classes.
[Link] a base class Animal with a method makeSound(),
and a derived class Dog that inherits from Animal and
overrides makeSound().
8. Create three classes: Animal → Mammal → Human, where
each class adds a specific behavior.(Multilevel).
9. Write a Java program that defines a class Person with a
default constructor that prints a message when an object is
created.
10. Create a class Student with a parameterized constructor
that takes name and age as arguments and initializes the
object's properties.
11. Write a Java program where a constructor checks a
condition (e.g., negative balance in a BankAccount) and
throws an exception if invalid data is provided.
12. Write a Java program that takes two numbers from the
user and performs division. Use a try-catch block to handle
division by zero.
13. Write a program that defines a custom exception
InvalidAgeException and throws it if the user enters an age
less than 18.
14. Write a Java program where a class Shape has overloaded
area() methods to calculate:
• Area of a circle (using radius)
• Area of a rectangle (using length and breadth)
• Area of a triangle (using base and height)
15. Create a base class Bank with a method getInterestRate(),
and override it in subclasses SBI, ICICI, and HDFC to return
different interest rates.

You might also like