0% found this document useful (0 votes)
15 views

UNIT I JAVA

JAVA CONCEPTS
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

UNIT I JAVA

JAVA CONCEPTS
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

UNIT I

MCQs (Multiple Choice Questions)


1. Which of the following is NOT a feature of Object-Oriented
Programming (OOP)?
o A) Encapsulation
o B) Abstraction
o C) Procedural programming
o D) Inheritance
Answer: C) Procedural programming
2. What does JVM stand for?
o A) Java Variable Manager
o B) Java Virtual Machine
o C) Java Visual Model
o D) Java Verified Machine
Answer: B) Java Virtual Machine
3. Which of the following data types is used to store a single character
in Java?
o A) String
o B) int
o C) char
o D) boolean
Answer: C) char
4. Which of the following statements about constructors in Java is
TRUE?
o A) A constructor cannot have parameters.
o B) A constructor is called when an object is created.
o C) A constructor can return a value.
o D) A constructor must be declared as static.
Answer: B) A constructor is called when an object is created.
5. What is the default value of a boolean variable in Java?
o A) true
o B) false
o C) 0
o D) null
Answer: B) false
6. Which of the following is the correct way to declare an array of
integers in Java?
o A) int[] arr;
o B) int arr[];
o C) Both A and B
o D) None of the above
Answer: C) Both A and B
7. Which of the following is used to declare a static method in Java?
o A) static void methodName()
o B) void static methodName()
o C) static methodName()
o D) void methodName()
Answer: A) static void methodName()
8. Which of the following keywords is used to prevent the inheritance of
a class in Java?
o A) private
o B) protected
o C) final
o D) static
Answer: C) final
9. What is the default value of an object reference variable in Java?
o A) 0
o B) null
o C) undefined
o D) "null"
Answer: B) null
10.Which method is used to compare two strings in Java?
o A) equals()
o B) ==
o C) compareTo()
o D) both A and C
Answer: D) both A and C
11.What will be the output of the following code?
12.String str = "Java";
13.str = str + " Programming";
14.System.out.println(str);
o A) Java
o B) Java Programming
o C) JavaProgramming
o D) Error
Answer: B) Java Programming
15.Which of the following is the correct syntax for type casting in Java?
o A) (int) variable
o B) variable(int)
o C) int(variable)
o D) cast(int) variable
Answer: A) (int) variable
16.What is the primary purpose of the 'this' keyword in Java?
o A) To refer to the current class instance variable
o B) To create a new object
o C) To invoke a constructor
o D) To invoke the parent class constructor
Answer: A) To refer to the current class instance variable
17.Which of the following is the correct way to define a constant in
Java?
o A) final int MAX = 100;
o B) const int MAX = 100;
o C) static final int MAX = 100;
o D) A and C are correct
Answer: D) A and C are correct
18.What is the correct way to create a new instance of a StringBuffer
object in Java?
o A) StringBuffer sb = new StringBuffer("Hello");
o B) StringBuffer sb = new StringBuffer();
o C) Both A and B
o D) StringBuffer sb = new String("Hello");
Answer: C) Both A and B
19.What will the following code output?
20.int x = 10;
21.System.out.println(x++);
o A) 9
o B) 10
o C) 11
o D) Error
Answer: B) 10
22.What is the default value of an int variable in Java?
o A) 0
o B) 1
o C) null
o D) undefined
Answer: A) 0
23.What is the role of the static block in Java?
o A) To initialize static variables
o B) To define the entry point of a program
o C) To define non-static variables
o D) To execute code when an object is created
Answer: A) To initialize static variables
24.Which of the following operators is used for string concatenation in
Java?
o A) +
o B) &&
o C) ||
o D) &
Answer: A) +
25.Which of the following classes can be used to manipulate strings in
Java?
o A) String
o B) StringBuilder
o C) StringBuffer
o D) All of the above
Answer: D) All of the above
26.Which keyword is used to create a subclass in Java?
o A) implements
o B) extends
o C) super
o D) inherits
Answer: B) extends
27.Which of the following is NOT a primitive data type in Java?
o A) int
o B) boolean
o C) char
o D) String
Answer: D) String
28.Which method is used to get the length of a string in Java?
o A) getLength()
o B) length()
o C) size()
o D) getSize()
Answer: B) length()
29.What will be the output of the following code?
30.String str1 = "abc";
31.String str2 = "abc";
32.System.out.println(str1 == str2);
o A) true
o B) false
o C) Compilation error
o D) Runtime error
Answer: A) true
33.What is the purpose of the 'final' keyword in Java?
o A) To declare a constant variable
o B) To prevent method overriding
o C) To prevent inheritance
o D) All of the above
Answer: D) All of the above

5-Mark Questions
1. Explain the history of Java and its significance in modern
programming.
o Discuss the origin of Java, its evolution, and its primary features
such as platform independence, object-orientation, and simplicity.
Highlight its major milestones, including the release of Java 1.0,
Java 2, and the transition to the current versions of Java.
2. Explain the architecture of JVM and its components.
o Define the Java Virtual Machine (JVM) and explain its components
like the class loader, runtime data areas, execution engine, and
garbage collector. Discuss how JVM enables Java’s platform
independence and ensures code execution on any device.
3. What is type casting in Java? Explain the differences between
implicit and explicit casting.
o Provide examples of both types of casting and explain when and
how each is used. Discuss automatic promotion of smaller data
types to larger ones (implicit) and manual casting (explicit).
4. What are static variables, methods, and blocks in Java? Provide
examples of their use.
o Discuss the concept of static variables and methods, including their
lifecycle and how they differ from instance members. Explain
static blocks and their role in initialization.
5. Explain the difference between String and StringBuffer in Java.
o Discuss the immutability of String and the mutability of
StringBuffer. Explain the performance benefits of using
StringBuffer for string manipulations and the scenarios where each
should be used.

10-Mark Questions
1. Discuss the object-oriented principles in Java with examples.
o Explain the four main principles of OOP: Encapsulation,
Abstraction, Inheritance, and Polymorphism. Provide examples for
each and demonstrate how these principles help in designing
maintainable and reusable code in Java.
2. Describe the scope and lifetime of variables in Java. How do local,
instance, and static variables differ in terms of scope and lifetime?
o Explain the scope and lifetime of local, instance, and static
variables with examples. Discuss how these variables are created
and destroyed during program execution, and the impact of
their scope on access.
3. Write a Java program to demonstrate the usage of constructors and
methods.
o Write a program that defines a class with both parameterized and
default constructors, and methods for performing operations.
Provide examples that show the constructor and method usage in
object creation and manipulation.
4. Explain the control statements in Java (if, switch, for, while, do-
while) with examples.
o Provide detailed examples of each control statement (if, switch, for
loop, while loop, and do-while loop). Discuss their syntax, usage,
and differences.
5. What are arrays in Java? Explain the differences between one-
dimensional and multi-dimensional arrays with examples.
o Define arrays and explain the process of declaring, initializing, and
accessing elements in one-dimensional and multi-dimensional
arrays. Provide examples for both types of arrays.

You might also like