0% found this document useful (0 votes)
27 views5 pages

JP Assignment 2&3

This document is a Java programming assignment consisting of multiple-choice questions covering various concepts such as object creation, class definitions, inheritance, method overriding, and array handling. The assignment is designed to test the understanding of Java programming fundamentals. It includes questions on keywords, access modifiers, and control structures.

Uploaded by

mrvenomousx
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)
27 views5 pages

JP Assignment 2&3

This document is a Java programming assignment consisting of multiple-choice questions covering various concepts such as object creation, class definitions, inheritance, method overriding, and array handling. The assignment is designed to test the understanding of Java programming fundamentals. It includes questions on keywords, access modifiers, and control structures.

Uploaded by

mrvenomousx
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/ 5

Java Programming

Assignment: 2 & 3
Date: 7 April, 2025 Time: 50 mins

Name: __________________ Roll no: ________________

1. Which keyword is used to create 7. Which method is automatically


an object in Java? called when an object is created?
a) class a) main()
b) new b) init()
c) object c) constructor()
d) create d) Constructor (with class name)
2. Which of the following defines a 8. Which keyword is used to define a
class correctly? method that cannot be
a) class Car() overridden?
b) def class Car a) const
c) class Car { } b) final
d) Car class { } c) static
3. What is the purpose of a d) private
constructor?
a) Destroy objects 9. What is inheritance in Java?
b) Create arrays a) Copying one class into another
c) Initialize objects b) Creating multiple classes from one
d) Convert types class
4. Which of the following allows c) Acquiring properties of one class
multiple methods with the same by another
name in a class? d) Declaring methods in classes
a) Method overriding 10. Which keyword is used to inherit a
b) Method hiding class?
c) Method overloading a) inherits
d) Method nesting b) this
5. What is the correct syntax to c) extends
access a class member? d) superclass
a) object->member 11. What is method overriding?
b) object.member a) Declaring multiple methods with
c) object:member the same name and parameters
d) object#member b) Using a superclass method as-is
6. Which keyword defines a static c) Redefining a method in a subclass
member? d) None of the above
a) const 12. What happens if a class is declared
b) shared final?
c) static a) It cannot be instantiated
d) class b) It cannot be inherited
c) Its variables cannot be changed c) int arr() = new int[5];
d) It cannot have a main method d) int arr = new int[];
13. The finalize() method is used 20. What is the index of the first
for: element in an array?
a) Compiling code a) -1
b) Managing memory before garbage b) 0
collection c) 1
c) Initializing objects d) Depends on the compiler
d) Protecting methods 21. How do you declare a 2D array?
14. Which keyword is used to prevent a) int arr = new int[2];
a method from being overridden? b) int arr[][] = new int[3]
a) protected [3];
b) private c) int arr[] = new int[3][3];
c) static d) array arr[2][2];
d) final 22. Which method returns the length
15. An abstract class: of a string in Java?
a) Cannot contain concrete methods a) size()
b) Cannot be extended b) length
c) Cannot be instantiated c) length()
d) Must contain only variables d) getLength()
16. Which of the following is a valid
abstract method? 23. Which package contains the
a) void draw() {} Vector class?
b) abstract void draw(); a) java.io
c) void draw() = 0; b) java.util
d) draw() abstract; c) java.vector
d) java.lang
17. Which access modifier provides 24. Which of these is a wrapper class
the least accessibility? for int?
a) public a) Int
b) private b) IntClass
c) protected c) Integer
d) default d) intObject
18. Which access modifier allows 25. What is autoboxing in Java?
visibility within the same package a) Converting an object to a
only? primitive
a) private b) Automatically importing classes
b) default c) Converting a primitive to a
c) public wrapper class
d) protected d) Wrapping methods in classes

19. How is a one-dimensional array 26. Which of the following can be


declared in Java? overloaded in a class?
a) int arr[] = new int[5]; a) Constructors only
b) int[] arr = int[5]; b) Methods only
c) Both methods and constructors methods
d) Neither b) Must be inherited to be used
27. Which constructor is provided by c) Can be instantiated directly
Java if none is defined? d) Can only contain variables
a) Copy constructor 35. Which keyword is not used for
b) Parameterized constructor visibility control in Java?
c) Default constructor a) private
d) Private constructor b) public
28. What does this keyword refer to? c) secure
a) Current method d) protected
b) Superclass 36. What is the default value of an
c) Current object uninitialized array of integers?
d) Main class a) 0
29. Which keyword is used to call a b) null
superclass constructor? c) undefined
a) super() d) garbage
b) this() 37. Which of the following is true
c) parent() about String in Java?
d) base() a) Strings are mutable
30. Which of the following is true b) Strings are objects
about static methods? c) Strings are stored as arrays
a) Can access non-static data directly d) Strings require special class
b) Can only access static data imports
c) Can use this keyword 38. What does toString() method do
d) Always abstract in Java?
31. What will happen if you try to a) Converts int to string
override a final method? b) Returns string representation of an
a) Compilation error object
b) Runtime error c) Parses a string
c) Works normally d) Converts string to char array
d) Skips method 39. Which method is used to add an
32. Which of the following defines element to a Vector?
polymorphism in Java? a) insert()
a) Abstraction b) append()
b) Overloading and Overriding c) add()
c) Inheritance only d) push()
d) Encapsulation 40. Which wrapper class method
33. Which of these allows abstract converts a string to integer?
methods? a) Integer.toInt()
a) Interface b) Integer.parseInt()
b) Final class c) parse.Integer()
c) Constructor d) String.toInt()
d) Static block
34. Which statement is true about an 41. Which of the following is an
abstract class? arithmetic operator in Java?
a) Cannot have any implemented a) &&
b) ++ 48. Which of the following is a bitwise
c) + operator?
d) == a) &&
b) ||
42. What will be the result of 10 % 3 in c) &
Java? d) ==
a) 1
b) 0 49. The instanceof operator is an example
c) 3 of a:
d) 10 a) Logical operator
b) Special operator
43. Which operator is used to check if two c) Bitwise operator
values are equal? d) Relational operator
a) =
b) == 50. The logical operator || returns true if:
c) != a) Both operands are false
d) && b) One operand is true
c) Both operands are true
44. Which operator increases the value of a d) None of the above
variable by 1?
a) -- 51. Which statement is used for decision-
b) ++ making in Java?
c) += a) loop
d) ** b) switch
c) if
45. What is the result of the expression 5 + d) class
2 * 3?
a) 21 52. What is the output of the following code:
b) 11
c) 13 if (true)
System.out.print("Hello");
d) 7
else
System.out.print("World");
46. What is the precedence of arithmetic
operators in Java? a) Hello
a) +, -, *, / b) World
b) *, / before +, - c) HelloWorld
c) Left to right d) Error
d) Equal for all
53. Which of the following is used to handle
47. What type of operator is ?: in Java? multiple conditions?
a) Logical a) switch
b) Assignment b) if
c) Conditional c) if-else
d) Bitwise d) else-if ladder
54. In a nested if-else statement, the else 58. Which of the following is the correct for
part belongs to: loop syntax?
a) The nearest if a) for x in range(10)
b) The outermost if b) for(int i = 0; i < 10; i++)
c) All if blocks c) loop(i = 0; i < 10; i++)
d) None d) for i in 10

55. Which keyword is used to compare a 59. The do-while loop evaluates the
single variable with multiple values? condition:
a) if a) Before the loop starts
b) else b) At the beginning of each iteration
c) switch c) At the end of each iteration
d) compare d) Only once

56. What type of loop is a while loop? 60. What will the following code output?
a) Entry controlled
b) Exit controlled int i = 0;
while(i < 3) {
c) Conditional System.out.print(i);
d) Counter controlled i++;
}
57. Which loop is guaranteed to execute at
least once? a) 0 1 2
a) while b) 1 2 3
b) do-while c) 0 1 2 3
c) for d) Infinite loop
d) None

You might also like