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

Java Programming Assignment 2

Uploaded by

shaikmehnazanjum
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)
4 views2 pages

Java Programming Assignment 2

Uploaded by

shaikmehnazanjum
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
You are on page 1/ 2

Java Programming Assignment 2

Question 1:
Write a Java program to demonstrate the usage of return types and arguments. Create a
method that takes two integers as arguments and returns their sum. Then, call this method
from the main method and display the result.

Clarifications:
1. Define a method that takes two integer arguments and returns their sum.
2. In the main method, call the method with appropriate arguments and display the
returned result.
3. Ensure the correct return type and arguments are used for the method.

Expected Output:
Sum of 5 and 10: 15

Question 2:
Explain the concept of 'public static void main' in Java. Write a program that demonstrates
the execution of a simple 'public static void main' method, and explain its components:
'public', 'static', 'void', and 'main'.

Clarifications:
1. Define the 'public static void main' method in your program.
2. Explain the purpose of 'public', 'static', 'void', and 'main' in the method declaration.
3. Implement a simple program that outputs 'Hello, World!' using the main method.

Question 3:
Write a Java program to demonstrate the concepts of classes, objects, and constructors.
Create a class 'Student' with attributes like 'name', 'age', and 'grade'. Use a constructor to
initialize these attributes, and then create an object of the class in the main method to
display the student's information.

Clarifications:
1. Create a 'Student' class with attributes 'name', 'age', and 'grade'.
2. Define a constructor to initialize the attributes.
3. In the main method, create an object of the 'Student' class and display its information.
Expected Output:
Student Information:
Name: John Doe
Age: 20
Grade: A

Question 4:
Write a Java program to demonstrate inheritance, interfaces, and method overriding. Create
a superclass 'Animal' with a method 'sound'. Then, create a subclass 'Dog' that overrides the
'sound' method. Use an interface 'Playable' that defines a 'play' method, and have 'Dog'
implement the 'Playable' interface.

Clarifications:
1. Create an 'Animal' class with a method 'sound'.
2. Create a 'Dog' class that inherits from 'Animal' and overrides the 'sound' method.
3. Define an interface 'Playable' with a 'play' method, and implement it in the 'Dog' class.
4. Demonstrate the use of inheritance and method overriding in the main method.

Expected Output:
Dog makes a sound: Woof
Dog can play: Yes

Submission Guidelines:
1. Create a folder on your Google Drive for the assignment.
2. Take full-screen screenshots of each task, including both the complete code and the
executed output from your system's IDE (online compiler screenshots are not valid).
3. Do not crop or edit the screenshots in any way to maintain clarity.
4. Upload the full-screen screenshots into the folder.
5. After uploading the screenshots, get the shareable link to the folder.
6. Submit the shareable link in the assignment submission section.

You might also like