[Go to site: main page, start]

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

Java Programming Exercises and Solutions

The document outlines a series of programming tasks and exercises in Java, including creating classes, methods, and interfaces, as well as implementing concepts like recursion, abstraction, and operator overloading. Each task includes a brief description of the expected output and functionality, such as printing college names, swapping numbers, and managing bank accounts. The exercises are designed to enhance understanding of object-oriented programming principles and Java syntax.

Uploaded by

mistikhattar
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)
4 views5 pages

Java Programming Exercises and Solutions

The document outlines a series of programming tasks and exercises in Java, including creating classes, methods, and interfaces, as well as implementing concepts like recursion, abstraction, and operator overloading. Each task includes a brief description of the expected output and functionality, such as printing college names, swapping numbers, and managing bank accounts. The exercises are designed to enhance understanding of object-oriented programming principles and Java syntax.

Uploaded by

mistikhattar
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

1. Write a program to print your college name.

Code: Output:

2. Write a Java Program to take two inputs (name and college name)
through command line argument and print as follows: <name> is a
[Link] student of <college name> college.
Code: Output:

3. Write a program to find the reverse of a given integer number (1st


day using static i/p and 2nd day using command-line argument).
Code: Output:

4. Write a Java Program to swap two numbers using the bitwise


operator.
Code: Output:

5. Write a program to find the factorial of a given integer number


using recursion.
Code: Output:

6. Create a class; make its instance variable and method. Use them
from main, declared in different class.
Code: Output:

1
7. Create a class; put a method inside this class which will return a
class reference return same class and/or different class object.
Code: Output:

8. Write a JAVA Program to make a Student class with proper


attributes like roll no, name, stream, and college.
Code: Output:

9. Design a class to represent a Bank Account. Include the following


things: Fields • Name of the depositor • Account number • Type of
account • Balance amount in the account
Methods
• To assign initial values • To deposit an amount • To withdraw an
amount after checking balance • To display the name and balance
Code: Output:

10. Overload the constructors for class Box for cube and cone and
also display its volume.
Code: Output:

2
11. Create a class with a method void show () and make 3 subclasses
of it and all subclasses have void show () method overridden and call
those methods using their class references.
Code: Output:

12. Check without having any abstract method/s whether a class can
be abstract; if so, then use that concrete method/s from another
class having main method.
Code: Output:

13. Create an abstract class with three abstract methods check


whether you can we override only few methods (not all methods) in
sub class or not.
Code: Output:

14. Assume that a bank maintains two kinds of account for its
customers, one called savings account and other called current
account. The savings account provides compound interest and
withdrawal facilities but no cheque book facility. The current account
provides cheque book facility but no interest. Current account
holders should also maintain a minimum balance (say Rs. 1000) and
if the bal ance falls below this level a service charge is imposed (say
Rs. 100). Create a class Account that stores customer name, account
number and type of account. From this class derive two classes
Curr_Acct and Savn_Acct respectively to make them more specific to
their requirements.

Include the necessary methods to achieve the following tasks:


a. Accept deposit from a customer and update the balance.
b. Display the balance.
c. Compute and deposit interest.
d. Permit withdrawal and update the balance.
3
e. Check for minimum balance, impose penalty, if necessary, and
update the balance. Use constructors to initialize the class members.
Code: Output:

15. Create an interface named Shape with a field pie (=3.14). Create
two subclasses of it named Circle and Rectangle create object of the
two classes and calculate their area.
Code: Output:

16. Create two interfaces, each with two methods. Inherit a new
interface from the two, adding a new method. Create a class by
implementing the new interface and also inheriting from a concrete
class. In main (), create an object of derived class and call the
methods. [do all without package statement]
Code: Output:

4
17. Show that static block is executed at the time of class loading and
also the order of execution of these blocks (for multiple blocks/
inherited block).
Code: Output:

18. Create an interface containing three methods, in a package


‘pkgOne’. Implement the interface from a class under package
pkgTwo. From main, under working directory, create object of the
class and call methods of interface.
Code: Part-1 Output:

Part-2

Part-3

You might also like