0% found this document useful (0 votes)
3 views8 pages

Java Assignment Solutions

The document contains a series of Java programming assignment questions and solutions focusing on Object-Oriented Programming (OOP) principles, including classes, objects, inheritance, and exception handling. It also includes practical coding tasks such as creating threads, implementing interfaces, and demonstrating various inheritance types. The assignments aim to enhance understanding of Java programming concepts and their applications.

Uploaded by

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

Java Assignment Solutions

The document contains a series of Java programming assignment questions and solutions focusing on Object-Oriented Programming (OOP) principles, including classes, objects, inheritance, and exception handling. It also includes practical coding tasks such as creating threads, implementing interfaces, and demonstrating various inheritance types. The assignments aim to enhance understanding of Java programming concepts and their applications.

Uploaded by

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

Java Programming Assignment Solutions

Q1. Explain the four fundamental principles of Object-Oriented Programming. How do


these principles enhance software development?

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q2. Discuss the concept of classes and objects in OOP. How do they relate to each
other, and how do they form the foundation of object-oriented design?

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q3. What is inheritance in Object-Oriented Programming? Describe the different


types of inheritance with examples.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q4. Write a Java program to create your own exception for NegativeValueException if
the user enters a negative value.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q5. Write a Java program to create two threads and execute simultaneously.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q6. Write a Java program to print a basic calculator.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q7. Write a Java program to print the 2nd highest element in an array by taking
user input.

Solution:
[Your solution/code here]

--------------------------------------------------------------------------------

Q8. Write a Java program to check whether a year is a leap year or not.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q9. Write a Java program to accept user input using command-line arguments and
calculate the sum of two integer numbers.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q10. Write a Java program that creates a class Shape with methods to calculate the
area of different shapes (circle, square, and rectangle) using method overloading.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q11. Write a Java program to implement multiple inheritance using interfaces and
demonstrate how methods from multiple interfaces can be accessed in a class.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q12. Write a Java program to create an interface and extend it to another


interface, then implement the extended interface in a class to demonstrate
interface extension.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q13. Write a Java program to create a class with a method that accepts an object as
a parameter and returns an object. Demonstrate this with appropriate examples.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q14. Write a Java program to implement an abstract class 'Appliance' with an


abstract method turnOn(). Create subclasses 'Fan' and 'TV' that implement turnOn()
in their own way.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q15. Write a Java program to create an abstract class 'Employee' with an abstract
method calculateSalary(). Implement subclasses 'FullTimeEmployee' and
'PartTimeEmployee' that provide their own implementations of calculateSalary().

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q16. Write a Java program to demonstrate the use of the super keyword to call a
parent class method.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q17. Write a Java program to show how a subclass constructor calls the superclass
constructor using super().

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q18. Write a Java program to create a simple abstract class with one abstract
method and implement it in a subclass.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q19. Write a Java program to demonstrate method overriding in a parent and child
class.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q20. Write a Java program to create an interface with one method and implement it
in a class.

Solution:
[Your solution/code here]

--------------------------------------------------------------------------------

Q21. Implement a Java method that performs division of two integers provided by the
user. Use try-catch-finally to handle ArithmeticException.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q22. Write a Java program that demonstrates single inheritance using a base class
Animal and a derived class Dog.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q23. Write a Java program that demonstrates multilevel inheritance using base class
Animal, derived class Dog, and subclass BabyDog.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q24. Write a Java program that demonstrates hierarchical inheritance where two
different classes (Dog and Cat) inherit from a single superclass Animal.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q25. Write a Java program that demonstrates multiple inheritance using interfaces.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q26. Write a Java program that demonstrates constructor overloading with different
parameterized constructors in a class Student.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q27. Write an abstract class Vehicle with an abstract method start(). Create two
subclasses Car and Bike that implement the start() method.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q28. Define user-defined methods for various argument/return type combinations.


Call all from main.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q29. Write a Java program to check whether a number is Palindrome or Not.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q30. Write a Java program to reverse a user input array.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q31. What is synchronization? How many types? Explain.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q32. Write a Java program to find the factorial value of the given number using
user-defined package concept.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q33. What is a Data Type? How to declare a variable in Java.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q34. Is switch better than if-else-if? Justify.


Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q35. What are Layout Managers in Java? Explain.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q36. List out any 10 AWT classes and their syntax.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q37. What is a collection class? Explain.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q38. Write a Java program to implement a simple calculator using methods for
arithmetic operations.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q39. Write a Java program to find the factorial of a given number using a for loop.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q40. Write a Java program to demonstrate method overloading.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q41. Write a Java program to show how to use the final keyword with a class and
method to prevent inheritance and overriding.
Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q42. Write a Java program to implement multilevel inheritance and show method calls
from different levels.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q43. Write a Java program to implement method overriding with superclass and
subclass.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q44. Write a Java program to take user input for different data types using the
Scanner class.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q45. Write a Java program to demonstrate static variables with object counter.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q46. Write a Java program to show abstract class with both abstract and non-
abstract methods.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

Q47. Write a Java program to demonstrate multilevel inheritance and constructor


execution from parent to child.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------
Q48. Write a Java program to implement hierarchical inheritance with multiple
subclasses inheriting from a parent class and overriding a method.

Solution:

[Your solution/code here]

--------------------------------------------------------------------------------

You might also like