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

Java Bits

The document contains a series of multiple-choice questions and answers related to Java programming concepts, including Object-Oriented Programming principles, data types, control statements, and methods. Key topics include encapsulation, input handling, loops, constructors, and operators. Each question is followed by the correct answer, providing a quick reference for Java programming knowledge.

Uploaded by

ng207441
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

Java Bits

The document contains a series of multiple-choice questions and answers related to Java programming concepts, including Object-Oriented Programming principles, data types, control statements, and methods. Key topics include encapsulation, input handling, loops, constructors, and operators. Each question is followed by the correct answer, providing a quick reference for Java programming knowledge.

Uploaded by

ng207441
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

[Link] of the following is not a principle of Object-Oriented Programming?

​ ​
a) Encapsulation b) Inheritance c) Compilation d) Polymorphism ​

C. compilation

2. In Java, the smallest unit of a program is called:​


a) Keyword b) Token ​ c) Identifier d) Constant

B. Token

3. Which keyword is used to take input from the user in Java?​


a) Input ​ b) cin ​ c) Scanner d) System

[Link]

4. Which escape sequence is used for newline in Java?​


a) \n ​ b) \t ​ c) \r ​ d) \

A. \n


5. Command line arguments in Java are passed to:​
a) class ​ b) main() method ​ c) constructor ​ d) JVM

B. main() method

6. Which of these is a primitive data type in Java?​


a) String ​ b) int ​ c) Scanner ​ d) System

[Link]

7. What is the default value of a boolean variable in Java?​


a) true ​ b) false ​ c) 0 d) null

[Link]


8. Type casting from double to int is called:​
a) Widening ​ b) Narrowing ​ c) Conversion ​ d) Promotion

[Link]

9. The symbol used for a ternary operator is:​


a) ? : ​ b) ++ ​ c) && ​ d) ||

A.?:

10. Which operator is used for bitwise AND?​
a) & ​ b) && ​ c) | ​ d) ^

A.&


11. Which control statement executes at least once?​
a) for ​ b) while ​ c) do-while d) switch

[Link]-while

12. Which keyword is used to exit from a loop immediately?​


a) stop ​ b) exit ​ c) break ​ d) continue

[Link]


13. Which loop is best suited when the number of iterations is known?​
a) for ​ b) while ​ c) do-while d) if-else

[Link]


14. Which keyword is used to create an object?​
a) class ​ b) this ​ c) new ​ d) create

[Link]


15. Which access specifier allows visibility only within the same class?​
a) public ​ b) private ​ c) protected d) default

[Link]

16. Constructors in Java:​


a) Have same name as class b) Return void c) Are inherited d) Can be abstract

A. Have same name as class


17. Overloaded constructors are identified by:​
a) Return type b) Access modifier c) Parameter list d) Class name

[Link] list​

18. Which keyword refers to the current object in Java?​
a) this ​ b) super ​ c) static ​ d) self

[Link]


19. Which modifier prevents inheritance of a class?​
a) static ​ b) private ​ c) final ​ d) abstract

[Link]


20. Which of the following is NOT a valid return type for a method?​
a) int ​ b) void ​ c) class ​ d) constructor

D. constructor


21. Method overloading means:​
a) Same name, different return type ​ b) Same name, different parameter list ​

c) Same name, same parameters d) Multiple classes using same method

B. Same name, different parameter list

22. Which keyword is used to call a parent class constructor?​


a) super ​ b) this ​ c) parent ​ d) base

[Link]

23. When a method calls itself, it is known as:​


a) Overloading b) Overriding c) Recursion d) Nesting

[Link]

.24. Which statement allows skipping the current iteration of a loop?​


a) break ​ b) continue c) exit ​ d) return

[Link]

25. Which loop is used in Java for iterating arrays easily?​


a) for ​ b) while ​ c) for-each d) do-while

[Link]-each
26. Which of the following is a valid identifier?

a) 123abc b) my-name c) _value d) float

C._value

27. A variable declared inside a method is called:​


a) Instance variable b) Local variable c) Static variable d) Global variable

B. Local variable


28. Which keyword is used to define a constant in Java?​
a) static ​ b) const ​ c) final ​ d) constant

[Link]

29. Which method is the entry point of every Java program?​


a) start() ​ b) main() ​ c) init() ​ d) run()

[Link]


30. Which operator is used for equality check?​
a) = ​ b) == ​ c) === ​ d) :=

B.==


31 The process of wrapping data and methods together is called
___Encapsulation___________.

32 The smallest unit of a Java program is called __Token____________

33 The [Link]() method is used for ___Output__________

34 The Scanner class is used for ______Taking input from user_____

35 The symbol ?: is called the ____Ternary Operator____________

36 A constructor has the same Name__________ as the class.

37 The keyword ____This______refers to the current object.

38 The keyword ___Final_______is used to create constants in Java.

39 In Java, && is the ___Logical AND________ operator.


40 A method that calls itself is known as ___Recursion_______

You might also like