0% found this document useful (0 votes)
37 views8 pages

Java Object-Oriented Programming Quiz

The document contains a series of multiple-choice questions and answers related to Object Oriented Programming concepts, Java syntax, and data types. It covers topics such as encapsulation, inheritance, polymorphism, and various types of errors in Java. Additionally, it includes definitions and differences between programming constructs like loops and data types.

Uploaded by

rajveerthkkr
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)
37 views8 pages

Java Object-Oriented Programming Quiz

The document contains a series of multiple-choice questions and answers related to Object Oriented Programming concepts, Java syntax, and data types. It covers topics such as encapsulation, inheritance, polymorphism, and various types of errors in Java. Additionally, it includes definitions and differences between programming constructs like loops and data types.

Uploaded by

rajveerthkkr
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

Choose the correct option.

1. Name the characteristics of Object Oriented Programming that hides the complexity and
provides a simple interface.
a. Encapsulation
b. Polymorphism
c. Abstraction
d. Inheritance
2. Which among the following operator is used to access individual members of an object?
a. . (dot)
b. + (plus)
c. -(minus)
d. / (divide)
3. Which among the following modifier is used in a ‘class’?
a. public
b. default
c. Both a and b
d. None of these
4. Which among the following is a valid class name?
a. Simple Interest
b. SimpleInterest
c. 1SimpleInterest
d. Simple@Interest
5. Which among the following is a valid object name?
a. obj1
b. 1obj
c. Obj 1
d. Obj#1
6. Which among the following is a valid float literal?
a. 12.36f
b. 12.36F
c. 12.36
d. Both a and b
7. Which among the following is a valid method of initialising?
a. boolean f=true;
b. boolean f=True;
c. boolean f=’true’;
d. None of these
8. Which among the following is not a punctuator?
a. ; semicolon
b. , comma
c. : colon
d. . dot
9. Which among the following is not a primitive data type?
a. int
b. float
c. String
d. char
10. If a is of type int and b is of type float what would be the resultant data type of a+b?
a. int
b. float
c. double
d. short
11. The method of Scanner class to accept a 64-bit floating point number is:
a. nextInt()
b. nextLong()
c. nextFloat()
d. nextDouble()
12. Classes, interfaces, methods, packages and variables are together called:
a. Keywords
b. Identifiers
c. User defined words
d. None of the these
13. The keyword that makes a variable constant is:
a. int
b. switch
c. final
d. All of these
14. How many bytes does float and double requires?
(a) Float-->2,Double-->4
(b) Float-->4,Double-->8
(c) Float-->8,Double-->16
(d) None of these
15. Which of the following statement is TRUE?
(a) / is the division operator whereas % is the modulus (remainder) operator.
(b) % is the division operator whereas / is the modulus (remainder) operator.
(c) / is the logical operator whereas % is the relational operator.
None of these
(d)
16. Which among the following is not a valid error in Java?
a. Syntax errors
b. Logical errors
c. Run-time errors
d. Technical errors
17. Which among the following Scanner methods allows us to input a number with a decimal point?
a. nextInt()
b. nextFloat()
c. nextDecimal()
d. nextPoint()
18. Assigning value to a variable during declaration is called.
a. Declaration
b. Assignment
c. Initialisation
d. None of these
19. Which among the following is used to represent single-line comment?
a. //
b. /*
c. \\
d. <!—
20. Which among the following is a logical error?
a. Missing semicolon
b. Mismatched braces in classes and methods.
c. Misspelled keywords and identifiers.
d. Addition is required but subtraction is performed.
21. Which among the following represents a syntax error?
a. Dividing an integer by zero.
b. Accessing an element that is out of bounds of an array.
c. Trying to store a value which is incompatible to a certain data-type.
d. Missing semicolon
22. If the data that is to take part in a calculation in a method is fixed, which form of input is
necessary?
a. Initialisation
b. Parameterised input
c. Scanner input
d. None of these
23. A loop programmed within another loop is known as:
a. Null loop
b. Nested loop
c. Void body loop
d. All of these
24. What is true about do while looping statement?
a. do while statement executes the code of a loop at least once
b. do while statement does not get execute if condition is not matched in the first iteration

c. do while statement checks the condition at the beginning of the loop


d. do while statement executes the code more than once always
25. The keyword which refers to the current object is:
a. new
b. private
c. void
d. this
26. Among the following which is a keyword:
a. every
b. all
c. case
d. each
27. The _________ are the words which have special meaning
a. Keywords
b. Identifier
c. Methods
d. Package
28. Primitive data types is.................

a. Arrays
b. Classes
c. Interfaces
d. boolean
29. Name the operator that is used to allocate memory space for an object.
a. Dot
b. new
c. Both a and b
d. None of these
30. What is the name given to a memory location called in Java?
a. Variable
b. Constant
c. Data Type
d. None of these
31. Which are the data types used in Java?
a. Primitive data type
b. Composite data type
c. Both a and b
d. None of these
32. How many objects can you create from a class?
a. One
b. Two
c. Three
d. Any number

33. _________are special symbols that define the structure of a program


a) Operator
b) Separator
c) Identifiers
d) Keyword
34. Escape sequence are always preceded by
a. /
b. //
c. \
d. *
35. They may begin with an alphabet, underscore or dollar sign
a. Operators
b. Separators
c. Identifiers
d. keyword
36. An identifier should never begin with
a. alphabet
b. number
c. $
d. _
37. An identifier should not have in between.
a. Space
b. number
c. $
d. _
38. An identifier should not have in between.
a. Full stop
b. Number
c. Underscore
d. $
39. These words cannot be used as an identifier
a. Reserved
b. Upper case
c. Lower case
d. alphabet
40. ____constants can take only two values ,true or false
a. boolean
b. int
c. double
d. byte
41. constants are enclosed within single quotes
a. float
b. char
c. String
d. double
42. ___ constant are enclosed within double quotes
a. float
b. char
c. String
d. double
43. ___ operators and other operators combine to build shorthand operators
a. Relational
b. Logical
c. Assignment
d. unary
44. The Scanner class is a class in
a. [Link]
b. [Link]
c. [Link]
d. [Link]
Answer the following questions

1. What is class?why is class called an object factory?


Ans: a class is a blueprint or template for creating objects. It defines the structure and behavior of objects including their
attributes (variables) and methods (functions). A class is called object factory as one can create multiple object of
a class

2. What is object?
Ans: object is an instance of a class, representing a specific entity with a defined state and behavior

3. What is Encapsulation?
Ans : Encapsulation is binding or wrapping the code and data in a single [Link] keeps them safe from outside
interference and misuses

4. What is inheritance?
Ans : Inheritance is the process by which one object acquires the properties ofanother object.
It allows the classes to share and reuse the data and methods.

5. What is Polymorphism?
Ans : Polymorphism allows two or more classes to respond to the same message in different ways thus we can have
multiple methods with same name but different functions. Polymorphism is achieved through method overloading
and method overriding.

6. What is Abstraction ?
Ans : Abstraction is representing essential feature without getting involved inentire system.

7. Write difference between while and do-while loop?

while loop do-while loop

while is an entry-controlled loop. do-while is an exit-controlled loop.

while loop checks the condition at the beginning of


do-while loop checks the condition at the end of the loop.
the loop.

do-while loop executes at least once, even if the


while loop executes only if the condition is true.
condition is false.

Syntax: Syntax:
while(test condition) do
{ {
… …
} }while(condition);
8. What are primitive and reference data type?

Ans : Primitive Data Types: There are eight primitive data types in Java
byte, short, int, long, float, double, boolean, and char.
Primitive types are predefined by the language and store the actual data value. They are not objects and do not have
methods.
Reference Data Types: also known as non-primitive types, are created by the programmer or are predefined classes in
Java. Examples include: string, arrays, classes, and interfaces.
9. What are the types of error ? write one example of each?

Ans : there are 3 types of error they are syntax errors, runtime errors, and logical errors.

Syntax Errors: These errors occur when the code violates the grammatical rules of Java. The compiler detects these
errors during compilation, and the program will not run until they are fixed.
eg : missing semicolon
Runtime Errors: These errors occur during the execution of the program. They are not detected during compilation eg:
dividing any number by zero
Logical Errors: These errors occur when the program compiles and runs without error , but gives incorrect output due to
mistake in the program's logic. eg: Addition is required but subtraction is performed.

10. What are jump statements in java?

Ans : Java uses three jump statements: break, continue, and return.

 break: it terminates the innermost enclosing while, do-while, for, or switch immediately and transfers control
to the following statement.
 continue: it terminates the current iteration of the innermost enclosing while,do- while, or for statement and
continues execution of the loop with the next iteration.
 return: Exits the current method and optionally returns a value.

You might also like