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

DCS - Java Programming - Part I

The document contains a series of multiple-choice questions and answers related to Java programming concepts, including data types, operators, control statements, object-oriented programming principles, and exception handling. Key topics covered include the Java Development Kit (JDK), memory allocation, selection statements, and constructors. It serves as a study guide for individuals looking to test their knowledge of Java programming fundamentals.

Uploaded by

Hamza Mukhtar
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)
6 views8 pages

DCS - Java Programming - Part I

The document contains a series of multiple-choice questions and answers related to Java programming concepts, including data types, operators, control statements, object-oriented programming principles, and exception handling. Key topics covered include the Java Development Kit (JDK), memory allocation, selection statements, and constructors. It serves as a study guide for individuals looking to test their knowledge of Java programming fundamentals.

Uploaded by

Hamza Mukhtar
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

Department of Computer Science

Java Programming

JDK stand for


A. Java development kit
B. Java declaration kit
C. Java definition kit
D. none
ANSWER: A

Java is case sensitive


A. yes
B. no
C. both
D. none
ANSWER: A

What is the range of byte data type in Java


A. -128 to 127
B. -327688 to 32767
C. -2147483648 to 2147483647
D. none
ANSWER: A

Which of these can be returned by the operator &.


A. Integer
B. Boolean
C. Character
D. Integer or Boolean
ANSWER: D

Literal can be of which of these data types.


A. integer
B. float
C. boolean
D. all of the mentioned
ANSWER: D

Which of these operators is used to allocate memory to array variable in Java.


A. malloc
B. alloc
C. new
D. new malloc
ANSWER: C

What is true about a break.


A. Break stops the execution of entire program
B. Break halts the execution and forces the control out of the loop
C. Break forces the control out of the loop and starts the execution of next iteration
D. Break halts the execution of the loop for certain time frame
ANSWER: B

Which of the following is used with the switch statement.


A. Continue
B. Exit
C. break
D. do
ANSWER: C

Which of the following is not a decision making statement?


A) if
B) if-else
C) switch
D) do-while
ANSWER: D

Which of these is an incorrect array declaration.


A. int arr[] = new int[5]
B. int [] arr = new int[5]
C. int arr[] = new int[5]
D. int arr[] = int [5] new
ANSWER: D

Which of the following can be operands of arithmetic operators.


A. Numeric
B. Boolean
C. Characters
D. Both Numeric & Characters
ANSWER: D

Decrement operator, −−, decreases the value of variable by what number.


A. 1
B. 2
C. 3
D. 4
ANSWER: A

Which of these selection statements test only for equality.


A. if
B. switch
C. if & switch
D. none of the mentioned
ANSWER: B

Which of these are selection statements in Java.


A. if()
B. for()
C. continue
D. break
ANSWER: A

Which of these jump statements can skip processing the remainder of the code in its body for a
particular iteration.
A. break
B. return
C. exit
D. continue
ANSWER: D

The while loop repeats a set of code while the condition is not met.
A. True
B. False
ANSWER: B

What is true about do statement.


A. do statement executes the code of a loop at least once
B. do statement does not get execute if condition is not matched in the first iteration
C. do statement checks the condition at the beginning of the loop
D. do statement executes the code more than once always
ANSWER: A

Which of the following is not a valid jump statement.


A. break
B. goto
C. continue
D. return
ANSWER: B

Which of the following is not a valid flow control statement.


A. exit()
B. break
C. continue
D. return
ANSWER: A

Which of these statements is correct.


A. true and false are numeric values 1 and 0
B. true and false are numeric values 0 and 1
C. true is any non zero value and false is 0
D. true and false are non numeric values
ANSWER: D

Which of these have highest precedence.


A. ()
B. ++
C. *
D. >>
ANSWER: A

What is the value stored in x in the following lines of Java code.


int x, y, z;
x = 0;
y = 1;
x = y = z = 8;
A. 0
B. 1
C. 9
D. 8
ANSWER: D

Which operator is used to invert all the digits in a binary representation of a number.
A. ~
B. <<<
C. >>>
D. ^
ANSWER: A

Which right shift operator preserves the sign of the value.


A. <<
B. >>
C. <<=
D. >>=
ANSWER: B

Process by which one object acquires the properties of another object.


A. Polymorphism
B. Encapsulation
C. Abstraction
D. Inheritance
ANSWER: D

Which of the following is not OOP concept in Java.


A. Inheritance
B. Encapsulation
C. Polymorphism
D. Compilation
ANSWER: D

Which concept of Java is a way of converting real world objects in terms of class.
A. Polymorphism
B. Encapsulation
C. Abstraction
D. Inheritance
ANSWER: C

Which of these keywords is used to make a class.


A. class
B. struct
C). int
D. none of the mentioned
ANSWER: A

Types of Constructor.
A. 2
B. 3
C. 4
D. 1
ANSWER: B

Which of these operators is used to allocate memory for an object.


A. malloc
B. alloc
C. new
D. give
ANSWER: C

Which of these statement is incorrect.


A. Every class must contain a main() method
B. Applets do not require a main() method at all
C. There can be only one main() method in a program
D. main() method must be made public
ANSWER: A

Which of these keywords is used to prevent content of a variable from being modified.
A. final
B. last
C. constant
D. static
ANSWER: A

Which of the following statements are incorrect.


A. static methods can call other static methods only
B. static methods must only access static data
C. static methods can not refer to this or super in any way
D. when object of class is declared, each object contains its own copy of static variables
ANSWER: D

Which of the following is a method having same name as that of it’s class.
A. finalize
B. delete
C. class
D. constructor
ANSWER: D

Which of these method of String class is used to obtain character at specified index.
A. char()
B. Charat()
C. charat()
D. charAt()
ANSWER: D

What would be the behaviour if this() and super() used in a method.


A. Runtime error
B. Throws exception
C. compile time error
D. Runs successfully
ANSWER: C

What is true about constructor.


A. It can contain return type
B. It can take any number of parameters
C. It can have any non access modifiers
D. Constructor cannot throw an exception
ANSWER: B

Which of this keyword can be used in a subclass to call the constructor of superclass.
A. super
B. this
C. extent
D. extends
ANSWER: A

Which of these method of Object class can clone an object.


A. Objectcopy()
B. copy()
C. Object clone()
D. clone()
ANSWER: C

Which of these keywords can be used to prevent inheritance of a class.


A. super
B. constant
C. class
D. final
ANSWER: D

Which of these is not abstract.


A. Thread
B. AbstractList
C. List
D. None of the Mentioned
ANSWER: A

Which of this keyword must be used to inherit a class.


A. super
B. this
C. extent
D. extends
ANSWER: D

Which of these is correct way of inheriting class A by class B.


A. class B + class A {}
B. class B inherits class A {}
C. class B extends A {}
D. class B extends class A {}
ANSWER: C

All classes in Java are inherited from which class.


A. [Link]
B. [Link]
C. [Link]
D. [Link]
ANSWER: D

If super class and subclass have same variable name, which keyword should be used to use super class.
A. super
B. this
C. upper
D. classname
ANSWER: A

What concepts come under Polymorphism in java.


A. Method overloading
B. Constructor overloading
C. Method overriding
D. All the above
ANSWER: D

Which polymorphism concept is applied to inheritance relationship in java programming.


A. Method overloading
B. Constructor overloading
C. Method overriding
D. None
ANSWER: C
Which feature comes under compile time polymorphism.
A. Method overloading
B. Constructor overloading
C. Method overriding
D. Both A and B
ANSWER: D

Container where related classes, interfaces and sub-package collect.


A. Class
B. Package
C. Function
D. Method
ANSWER: B

Java exception handling is managed via .....


A. 3 keywords
B. 5 variable
C. 5 keywords
D. 4 keywords
ANSWER: C

Which class is used in Interface


A. String
B. Abstract
C. Class
D. Extend

You might also like