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

Computer_JAVA-I

Uploaded by

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

Computer_JAVA-I

Uploaded by

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

Multiple Choice Questions

1 Which of the following is not OOPS concept in Java?


a) Inheritance
b) Encapsulation
c) Polymorphism
d) Compilation
2 When does method overloading is determined?
a) At run time
b) At compile time
c) At coding time
d) At execution time
3 Which concept of Java is achieved by combining methods and attribute into a class?
a) Encapsulation
b) Inheritance
c) Polymorphism
d) Abstraction

4 Java Source Code is compiled into .

5 A. .Obj
B. Source Code
C. Bytecode
D. .Exe
6 Single line comment starts with in Java.

7 A. /**
B. //
C. /*
D. None of these
8 How to compile java code in command prompt?

A. javac filename.java
B. java filename.java
C. javac filename
D. java filename
9 How to run java program in command prompt?

10 A. javac filename.java
11 B. java filename.java
C. javac filename
D. java filename
12 Java is case sensitive?

A. True
B. False
C. Depends On Complier
D. May be true or false
13 Default, public , protected, private are?

A. Access Modifier
B. Non-access Modifiers
C. Both A and B
D. It's variable
14 Java was designed by .

A. Microsoft
B. Mozilla Corporation
C. Sun Microsystems
D. Amazon Inc.
15 Java is a programming language

A. high-level
B. Middle-level
C. Low-level
D. None of the above
16 Which of the following are correct advantage of java?

A. Java is Simple
B. Java is Secure
C. Java is Portable
D. All of the above
17 Basic aim of java was to solve the problem of connecting many household machines
together.

18 A. Java data kit


B. Java defination kit
C. Java design kit
D. Java development kit
19 Modulus operator, %, can be applied to which of these?

A. Both Integers and floating - point numbers


B. Integers
C. Floating - point numbers
D. None of the mentioned
20 What is the output of relational operators?

A. Integer
B. Boolean
C. Characters
D. Double
21 Which of these is returned by "greater than", "less than" and "equal to" operators?

A. Integers
B. Floating - point numbers
C. Boolean
D. None of the mentioned
22 Which of these have highest precedence?

A. ()
B. ++
C. *
D. >>
23 Java array is a collection of .

A. similar type of elements


B. different type of element
C. heterogeneous data
D. Both A and C
24 Array data access using .

A. Operator
B. Variable
C. index
D. Pointer
25 At time of array initialization which is necessary to specify?

A. Row
B. Column
C. Row and Column
D. None of the above
26 Java Array can allocate .

A. Dynamic Memory
B. Static Memory
C. Both A and B
D. None of the above
27 Which of the following 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
28 Index in array start with .

A. -1
B. 0
C. 1
D. infinite
29 Which of the following is used to declare,construct, and initlaize an array?

A. int arr [] [] = {1, 2, 3, 4};


B. int [] arr = (1, 2, 3);
C. int [] arr = {};
D. int arr [] = {1, 2, 3};
30 We can calculate the length of an array using .

A. sizeof(array)
B. array.len
C. array.length
D. array.sizeof()
31 In java, array elements are stored in memory locations.

A. Random
B. Sequential
C. Sequential & Random
D. Binary search

32 What will be the output of the program?

class Main

public static void main(String args[]) {

int arr[] = {10, 20, 30, 40, 50};

for(int i=0; i < arr.length; i++)

System.out.print(" " + arr[i]);

}
A. 10 20 30 40 50
B. Compiler Error
C. 10 20 30 40
D. None of the above

33 What will be output for the following code?


class Main

public static void main(String args[])

int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};

int n = 6;

n = arr[arr[n] / 2];

System.out.print(n);

A. 3

B. 0
C. 6
D. 1

34 How to sort an array?

A. Array.sort()
B. Arrays.sort()
C. Collection.sort()
D. System.sort()

35 Which of these keywords is used to define interfaces in Java?

A. interface
B. Interface
C. intf
D. Intf

36 Which of these access specifiers can be used for an interface?

A. Public
B. private
C. Protected
D. All of the mentioned

37 Which of the following is a correct interface?

A. abstract interface A { abstract void print(); { }}


B. abstract interface A { print(); }
C. interface A { void print() { } }
D. interface A { void print(); }

38 What does an interface contain?

A. Method definition
B. Method declaration
C. Method declaration and definition
D. Method name
39 Package in Java is a mechanism to encapsulate a .

A. Classes
B. Sub Packages
C. Interfaces
D. All of the above
40 Which of these keywords is used to define packages in Java?

A. pkg
B. Pkg
C. package
D. Package

40An statement can be used to access the classes and interface of a different
package from the current package.

A. instanceOf
B. import
C. extends
D. implement

41Which of the following packages is used to includes classes to create user interface like Button and
Checkbox?

A. java.lang
B. java.net
C. java.awt
D. java.io

42 Which of the following is the correct way of importing an entire package "pkg"?

A. import pkg.
B. Import pkg.
C. import pkg.*
D. Import pkg.*

43 Which component is used to compile, debug and execute java program?


a) JVM
b) JDK
c) JIT
d) JRE

44 Which component is responsible for converting bytecode into machine specific code?
a) JVM
b) JDK
c) JIT
d) JRE

45 What is the extension of java code files?


a) .class
b) .java
c) .txt
d) .js

46 What is the extension of compiled java classes?


a) .class
b) .java
c) .txt
d) .js

47 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

48 What is the full form of JVM ?

A. Java Very Large Machine B. Java Verified Machine

C. Java Very Small Machine D. Java Virtual Machine

49 Which of the following would compile without error?


A. int a = Math.abs(-5);

B. int b = Math.abs(5.0);

C. int c = Math.abs(5.5F);
D. int d = Math.abs(5L);
50 Which Scanner class method is used to read integer value from the user?

1. next()
2. nextInteger()
3. nextInt()
4. readInt()
51 Which Scanner class method is used to read string value from the user?

1. next()
2. nextString()
3. nextLine()
4. Both 1 and 3
52 Which is the correct syntax to declare Scanner class object?

1. Scanner objectName= Scanner();


2. Scanner objectName= new Scanner();
3. Scanner objectName= Scanner(System.in);
4. Scanner objectName= new Scanner(System.in);
53 The name of a constructor and the name of a class are .
A) Same
B) Different
C) none
D) Both A and B
54 The purpose of a Java constructor is .

A) Initialization of variables with passed data


B) Writing custom code
C) Accepting other objects as inputs
D) All the above
55 Java constructor overloading follows principle in Object-Oriented programming.

A) Inheritance
B) Encapsulation
C) Polymorphism
D) None

56 What is the return type of a method that does not return any value?
a) int
b) float
c) void
d) double

57 What is the process of defining more than one method in a class differentiated by
method signature?
a) Function overriding
b) Function overloading
c) Function doubling
d) None of the mentioned
58 Which method can be defined only once in a program?
a) main method
b) finalize method
c) static method
d) private method

59 Which of this statement is incorrect?


a) All object of a class are allotted memory for the all the variables defined in the class
b) If a function is defined public it can be accessed by object of other class by inheritation
c) main() method must be made public
d) All object of a class are allotted memory for the methods defined in the class

60 Which of the following option leads to the portability and security of Java?

a. Bytecode is executed by JVM


b. The applet makes the Java code secure and portable
c. Use of exception handling
d. Dynamic binding between objects

61 Java method signature is a combination of .

A) Return type
B) Method name
C) Argument List
D) All the above

62 What is meant by the classes and objects that dependents on each other?

a. Tight Coupling
b. Cohesion
c. Loose Coupling
d. None of the above

63 Given
int values[ ] = {1,2,3,4,5,6,7,8,9,10};
for(int i=0;i< Y; ++i) System.out.println(values[i]);

Find the value of value[i]?

a. 10
b. 11
c. 15
d. None of the above
64 Which of the following is not a primitive data type?
a) Boolean
b) byte
c) string
d) double
65 Which of the following operators take (s) only integer operands?
a)%
b) ++ (post-increment)
c) ++(pre-increment)
d)none of these
66 Which of the following doesn’t have a superclass?
a) System
b) Object
c) Lang
d) Exception
67 Constant that cannot be changed are declared using the keyword
a) final
b) static
c) absatract
d) immutable
68 Which of the following can be used to copy data from one array to another?
a) System.clone
b) java.lang.toCopy
c) System.arraycopy
d) java.lang.clone
69 Which of the following keywords is used to declare exceptions that can possibly occur?
a) handle
b) throws
c) checked
d) manage
71 public class MyClass{
public static void main(String args[])
{ System.out.println(“In first main()”);
}
public static void main(char args[]){
System.out.println(‘a’);
}
}

A) The code will not compile and will give “Duplicate main() method declaration” error
B) The code will compile correctly but will give a runtime exception
C) The code will compile correctly and will print “In first main()” (without quotes) when it is
run
D) The code will compile correctly and will print “a” (without quotes) when it is run

72 Consider the statement “x=(a>b)?a:b”, then the value of x is 19 if a=19 and b=12
A) true

B) not supported

C) false

D) none of the above

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

Java? A.alloc B.malloc

C.new malloc D.new

74 Which of the following are not Java modifiers?

A.public B.private

C.friendly D.transient

75 The wrapping up of data and functions into a single unit is called

(a) Encapsulation (b) Abstraction


(c) Data Hiding (d) Polymorphism (e) Message passing.

76 In Java, declaring a class abstract is useful

(a) To prevent developers from further extending the class


(b) When it doesn’t make sense to have objects of that class
(c) When default implementations of some methods are not desirable
(d) To force developers to extend the class not to use its capabilities

77 A package is a collection of

(a) Classes (b) Interfaces (c) Editing tools


(d) Classes and interfaces
78 public class testincr
{
public static void main(String args[])
{
int i = 0;
i = i++ + i;
System.out.println(“I = ” +i);
}
}

(a) I = 0 (b) I = 1 (c) I = 2 (d) I = 3 (e) Compile-time Error.

79 Multiple inheritance means,

(a) one class inheriting from more super classes


(b) more classes inheriting from one super class
(c) more classes inheriting from more super classes
(d) None of the above

80 Which statement is not true in java language?

(a) A public member of a class can be accessed in all the packages.


(b) A private member of a class cannot be accessed by the methods of the same class.
(c) A private member of a class cannot be accessed from its derived class.
(d) A protected member of a class can be accessed from its derived class.

81 public class testmeth


{
static int i = 1;
public static void main(String args[])
{
System.out.println(i+” ,
“); m(i);
System.out.println(i);
}
public void m(int i)
{
i += 2;
}
}

(a) 1 , 3 (b) 3 , 1 (c) 1 , 1 (d) 1 , 0

82 For what values respectively of the variables gender and age would the Java
expression gender == 1 && age >= 65 become true?

(a) gender = 1, age = 60 (b) gender = 1, age = 50


(c) gender = 1, age = 65 (d) gender = 0, age = 70

83 public class Test {


public static void main(String[] args) {
String x = "abc";
String y = "abc";
x.concat(y);
System.out.print(x);
}
}

A. abc
B. abcabc
C. null

84 What will be the output of below code snippet?

String s1 = new String("java");


String s2 = new String("JAVA");
System.out.println(s1 = s2);

A. JAVA
B. java
C. true
D. false
85 String in Java is a?
a) class
b) object
c) variable
d) character array

86 Which of these method of String class is used to obtain character at specified index?
a) char()
b) Charat()
c) charat()
d) charAt()

87 Which of these keywords is used to refer to member of base class from a subclass?
a) upper
b) super
c) this
d) none of the mentioned

88 Which of these method of String class can be used to test to strings for equality?
a) isequal()
b) isequals()
c) equal()
d) equals()

89 Which of the following statements are incorrect?


a) String is a class
b) Strings in java are mutable
c) Every string is an object of class String
d) Java defines a peer class of String, called StringBuffer, which allows string to be altered

90 Which of these class is used to read characters and strings in Java from console?
a) BufferedReader
b) StringReader
c) BufferedStreamReader
d) InputStreamReader

91
1. class output
2. {
3. public static void main(String args[])
4. {
5. StringBuffer c = new StringBuffer("Hello");
6. StringBuffer c1 = new StringBuffer(" World");
7. c.append(c1);
8. System.out.println(c);
9. }
10. }
a)Hello b)World
c)Helloworld
d) Hello World

92

1. class output
2. {
3. public static void main(String args[])
4. {
5. StringBuffer s1 = new StringBuffer("Hello");
6. s1.setCharAt(1,x);
7. System.out.println(s1);
8. }
9. }
a) xello
b)xxxxx
c)Hxllo
d) Hexlo

93 Which of these methods can be used to writing console output?


a)print()
b) println()
c)write()
d) all of the mentioned

94 What is not the advantage of Reflection?

a) Examine a class’s field and method at runtime

b) Construct an object for a class at runtime

c) Examine a class’s field at compile time

d) Examine an object’s class at runtime

95 How private method can be called using reflection?


a) getDeclaredFields

b) getDeclaredMethods

c) getMethods

d) getFields

96 How private field can be called using reflection?

a) getDeclaredFields

b) getDeclaredMethods

c) getMethods

d) getFields

97 How to get the class object of associated class using Reflection?

a) Class.forName(“className”)

b) Class.name(“className”)

c) className.getClass()

d) className.getClassName()

98 What does foo.getClass().getMethod(“doSomething”, null) return?

a) doSomething method instance

b) Method is returned and we can call the method as method.invoke(foo,null);

c) Class object

d) Exception is thrown

99 Which method does not store string value after space?

A )next()

B) nextString()

C) nextLine()

D) Both A and C
100 Which is the correct syntax to declare Scanner class

object? A )Scanner objectName= Scanner();

B) Scanner objectName= new Scanner();

C) Scanner objectName= Scanner(System.in);

D) Scanner objectName= new Scanner(System.in);

You might also like