Moksha - Test 1 - Core Java
Moksha - Test 1
1. Define inheritance in Java and
provide an example.
2. Explain the concept of
encapsulation and its benefits in Java.
3. What is polymorphism? How does it
relate to method overriding?
4. Describe abstraction and provide
an example from real-world scenarios.
5. Differentiate between method
overloading and method overriding.
6. What is a constructor in Java?
How is it different from a method?
7. List and briefly explain the four
access modifiers in Java.
8. How do you declare a constant
variable in Java?
9. Define the terms "instance
variable" and "class variable".
10. Explain the purpose of the
'super' keyword in Java.
11. Explain the term "method
signature" in Java and its importance in method overloading.
12. Describe the concept of method
overriding in Java and how is it achieved and what are the rules?
13. What is a constructor chaining?
Provide an example of constructor chaining in Java.
14. Define the term "static
variable" in Java. How does it differ from an instance variable?
15. Explain the difference between a
reference variable and an object in Java.
16. Discuss the role of the 'this'
keyword in Java. When and how is it used?
17. Describe the purpose of the
'final' keyword in Java, including its usage with variables and methods.
18. Explain the significance of the
'abstract' keyword in Java classes and methods.
19. What is method hiding in Java?
Provide an example to illustrate the concept.
20. Describe the process of type
casting in Java. What is the difference between implicit and explicit casting?
21. Define the terms
"post-increment" and "pre-increment" operators in Java.
Provide examples of each.
22. Explain the difference between
'if', 'else if', and 'switch' statements in Java.
23. Describe the purpose of the
'while' loop in Java. Provide an example of its usage.
24. What is the 'do-while' loop in
Java? How does it differ from the 'while' loop?
25. Explain the use of the 'break'
and 'continue' statements in Java loops.
Coding Test
1.
Write
a Java class representing a 'Vehicle' with properties like 'make' and 'model'.
Include a constructor to initialize these properties.
2.
Create
a Java class for 'Circle' with a method to calculate and return its area.
3.
Implement
a 'Student' class with private variables for name and age, along with getters
and setters.
4.
Create
a Java program to demonstrate method overloading with two different methods to
calculate the area of a rectangle (one using length and width, the other using
diagonal).
5.
Develop
a 'BankAccount' class with methods to deposit and withdraw funds.
6.
Write
a Java class 'Employee' with private fields for name, salary, and an
'EmployeeInfo' method to display employee details.
7.
Implement
a 'Calculator' class with methods for basic arithmetic operations (+, -, *, /).
8.
Create
a 'Person' class with a private field for age. Implement a constructor that
sets the age, and handle cases where the age is negative.
9.
Design
a 'Book' class with properties like title, author, and price. Implement a
method to display book information.
10. Develop a Java program that uses
a 'Switch' statement to determine the day of the week based on an input number
(1 for Monday, 2 for Tuesday, and so on).
11. Write a Java program to calculate
the factorial of a given number using a loop.
12. Implement a program that
generates the Fibonacci sequence up to a specified number of terms.
13. Create a Java program that checks
whether a given number is prime or not.
14. Develop a Java program to
calculate the sum of all even numbers between 1 and a given number using a
'while' loop.
15. Write a Java program to find the
largest element in an array of integers.
16. Implement a program that prints
the multiplication table for a given number using a 'for' loop.
17. Create a Java program that
converts temperature from Fahrenheit to Celsius using the formula: Celsius =
(Fahrenheit - 32) * 5/9.
18. Write a Java program to calculate
the sum of digits of a positive integer.
19. Develop a Java program to find
the factorial of a given number using recursion.
20. Implement a simple calculator
program that takes two numbers and an operator (+, -, *, /) as input and
performs the corresponding operation.
Comments
Post a Comment