0% found this document useful (0 votes)
10 views26 pages

Java Object-Oriented Programming Exercises

The document outlines a series of Java programming assignments focused on object-oriented programming concepts. Each question requires students to write Java programs for various tasks, such as printing messages, performing arithmetic operations, and demonstrating inheritance and polymorphism. The assignments cover fundamental programming skills and concepts, providing a comprehensive learning experience.

Uploaded by

izharhussain1946
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)
10 views26 pages

Java Object-Oriented Programming Exercises

The document outlines a series of Java programming assignments focused on object-oriented programming concepts. Each question requires students to write Java programs for various tasks, such as printing messages, performing arithmetic operations, and demonstrating inheritance and polymorphism. The assignments cover fundamental programming skills and concepts, providing a comprehensive learning experience.

Uploaded by

izharhussain1946
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

Object oriented programing using java Page

code-104p

Assignment
Que.1: Write a java program to write “Hello World” and your name.
Ans: {input}

{output}

HARIOM 02913402024 1
Object oriented programing using java Page
code-104p

Que.2 Write a program to take two number as input and perform


addition, substraction, multiplications, and divisions.
Ans:
{INPUT}

HARIOM 02913402024 2
Object oriented programing using java Page
code-104p
{OUTPUT}

Que.3: Write a Java program to swap two numbers without using a third
variable.
Ans:

HARIOM 02913402024 3
Object oriented programing using java Page
code-104p
{OUTPUT}

Que.4: Write a Java program to check if a given number is even or odd.


Ans:

{OUTPUT}

HARIOM 02913402024 4
Object oriented programing using java Page
code-104p

Que.5: Write a Java program to create a menu driven calculator using


switch case.
Ans:

{OUTPUT}

HARIOM 02913402024 5
Object oriented programing using java Page
code-104p

Que.6: Write a Java program to find the largest of three numbers using if-
else.
Ans:

{OUTPUT}

Que.7: Write a Java program to print the multiplication table of a given


number.
Ans:

HARIOM 02913402024 6
Object oriented programing using java Page
code-104p
{output}

Que.8: Write a Java program to check whether a number is prime or not.


Ans:

{output}

HARIOM 02913402024 7
Object oriented programing using java Page
code-104p

Que.9: Write a Java program to calculate the factorial of a given number


using a loop.
Ans:

{output}

Que.10: Write a Java program to print the first N numbers in the Fibonacci
series.
Ans:

HARIOM 02913402024 8
Object oriented programing using java Page
code-104p

{output}

Que.11: Write a Java program to find the sum and average of elements in
an array.
Ans:

{output}

HARIOM 02913402024 9
Object oriented programing using java Page
code-104p

Que.12: Write a Java program to demonstrate user input using the


Scanner class.
Ans:

{output}

Q13: Write a Java program to read input using the BufferedReader class.
Ans:

{output}

HARIOM 02913402024 10
Object oriented programing using java Page
code-104p
Q14: Write a program to demonstrate the use of static variable, static
method, and static block.
Ans:

{output}

Q15: Write a program to demonstrate concept of this keyword.


Ans:
HARIOM 02913402024 11
Object oriented programing using java Page
code-104p

{output}

Q16: Write a Java program to demonstrate method overriding.


Ans:

HARIOM 02913402024 12
Object oriented programing using java Page
code-104p

{output}

Q17: Write a Java program to demonstrate multi-level and hierarchical


inheritance.
HARIOM 02913402024 13
Object oriented programing using java Page
code-104p
Ans:

{output}

Q18: Write a program declaring a Java class called SavingsAccount with


members accountNumber and balance.
Ans:

HARIOM 02913402024 14
Object oriented programing using java Page
code-104p

{output}

Q19: Write a Java program to create a class Student with attributes name,
roll_no, and marks.
Ans:

HARIOM 02913402024 15
Object oriented programing using java Page
code-104p

{output}

HARIOM 02913402024 16
Object oriented programing using java Page
code-104p
Q20: Write a Java program to create a class Rectangle with attributes
length and breadth.
Ans:

{output}

HARIOM 02913402024 17
Object oriented programing using java Page
code-104p
Q21: Write a Java program to demonstrate method overloading using a
Calculator class.
Ans:

{output}

HARIOM 02913402024 18
Object oriented programing using java Page
code-104p
Q22: Write a Java program to demonstrate run-time polymorphism.
Ans:

{output}

HARIOM 02913402024 19
Object oriented programing using java Page
code-104p
Q23: Write a Java program to implement constructor overloading.
Ans:

{output}

Q24: Write a Java program to demonstrate the use of the super keyword
in method overriding.
Ans:

HARIOM 02913402024 20
Object oriented programing using java Page
code-104p

{output}

Q25: Write a Java program to implement multiple inheritance in Java


using interfaces.
Ans:

HARIOM 02913402024 21
Object oriented programing using java Page
code-104p

{output}

Q26: Write a program to demonstrate the concept of abstract class with a


constructor and a final method.
Ans:

{output}

Q27: Write a program to implement an interface and override its


methods.

HARIOM 02913402024 22
Object oriented programing using java Page
code-104p

Ans:

{output}

Q28: Write a program to demonstrate method overloading by calculating


the area of a square, rectangle, and triangle.
Ans:

HARIOM 02913402024 23
Object oriented programing using java Page
code-104p

{output}

Q29: Write a program to demonstrate run-time polymorphism using


method overriding.
Ans:

HARIOM 02913402024 24
Object oriented programing using java Page
code-104p

{output}

HARIOM 02913402024 25
Object oriented programing using java Page
code-104p

Q30: Write a Java program to demonstrate encapsulation.


Ans:

{output}

HARIOM 02913402024 26

You might also like