CAF 2105 Advanced Java Programming Worksheet
Module 1
Part A – Multiple Choice Questions (20 b) object
Marks) c) new
(Each question carries 1 mark) d) construct
1. Which of the following is not a feature 10. Which method is the entry point for a
of Java? Java program?
a) Object-Oriented a) main()
b) Platform Independent b) start()
c) Pointer Arithmetic c) run()
d) Automatic Garbage Collection d) execute()
2. The JVM stands for: 11. Which control statement is used for
a) Java Virtual Machine multiple selection in Java?
b) Java Variable Method a) if
c) Java Verified Machine b) if-else
d) Java Visual Manager c) switch
3. Java was developed by: d) break
a) Bjarne Stroustrup 12. Which loop is guaranteed to execute
b) James Gosling at least once?
c) Dennis Ritchie a) for
d) Guido van Rossum b) while
4. The extension of a compiled Java file c) do-while
is: d) foreach
a) .java 13. A constructor must have:
b) .class a) Same name as class
c) .exe b) Return type void
d) .obj c) Static keyword
5. Which of these is used to import a d) Final keyword
package in Java? 14. If a constructor is not defined, Java
a) package provides:
b) import a) No constructor
c) include b) Default constructor
d) extends c) Copy constructor
6. Which operator is used to compare d) Destructor
two values in Java? 15. Method overloading means:
a) = a) Defining multiple methods with the
b) == same name but different parameters
c) := b) Defining multiple classes with same
d) equals name
7. Which of these is a logical operator in c) Using multiple constructors
Java? d) Overriding methods in subclass
a) & 16. Which of the following is not a
b) && primitive type in Java?
c) | a) int
d) all of the above b) float
8. The default value of a boolean c) String
variable in Java is: d) char
a) true 17. Which operator is used for string
b) false concatenation in Java?
c) 0 a) +
d) null b) &
9. Which keyword is used to create an c) .
object in Java? d) concat
a) create
18. Which of the following cannot be Q3.
overloaded in Java? class LoopTest {
a) Constructors public static void main(String[] args) {
b) Methods int i = 1;
c) main() method while (i <= 3) {
d) Operators System.out.print(i + " ");
19. The break statement is used to: i++;
a) Exit from loop }
b) Continue next iteration }
c) Terminate program }
d) Exit JVM Q4.
20. Which keyword is used to inherit a class Overload {
class in Java? void show(int a) {
a) extends System.out.println("Integer: " + a);
b) implements }
c) super void show(String s) {
d) import System.out.println("String: " + s);
}
Part B – Predict the Output (5 Questions × 2 public static void main(String[] args) {
Marks = 10 Marks) Overload obj = new Overload();
Q1. obj.show(100);
class Test { obj.show("Java");
public static void main(String[] args) { }
int x = 5, y = 10; }
System.out.println(x + y + " is result"); Q5.
System.out.println("Result is " + x + y); class SwitchDemo {
} public static void main(String[] args) {
} int day = 3;
switch (day) {
case 1: System.out.println("Mon");
Q2. break;
class Demo { case 2: System.out.println("Tue");
Demo() { break;
System.out.println("Constructor called"); case 3: System.out.println("Wed");
} break;
public static void main(String[] args) { default: System.out.println("Other");
Demo d1 = new Demo(); }
Demo d2 = new Demo(); }
} }
}
Part C – Write a Program (1 Question × 10 Marks = 10 Marks)
Q6. Write a Java program to create a Student class with data members: roll number, name, and
department. Use a constructor to initialize values and display the details of 3 students.