0% found this document useful (0 votes)
20 views27 pages

Cogni Java

The document consists of a series of multiple-choice questions related to Java programming concepts, including data types, OOP principles, method behavior, and access specifiers. Each question is followed by the correct answer, covering topics such as char data type range, boolean values, method overloading, and static methods. The questions also explore the output of various Java code snippets.

Uploaded by

p2004mondal
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)
20 views27 pages

Cogni Java

The document consists of a series of multiple-choice questions related to Java programming concepts, including data types, OOP principles, method behavior, and access specifiers. Each question is followed by the correct answer, covering topics such as char data type range, boolean values, method overloading, and static methods. The questions also explore the output of various Java code snippets.

Uploaded by

p2004mondal
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
You are on page 1/ 27

1. What is the numerical range of a char data type in Java?


a) -128 to 127​
b) 0 to 256​
c) 0 to 32767​
d) 0 to 65535​
Answer: d

2. Which of these coding types is used for data type characters in Java?​
a) ASCII​
b) ISO-LATIN-1​
c) UNICODE​
d) None of the mentioned​
Answer: c

3. Which of these values can a boolean variable contain?​


a) True & False​
b) 0 & 1​
c) Any integer value​
d) true​
Answer: d

4. Which of these occupy the first 0 to 127 in the Unicode character set used for
characters in Java?​
a) ASCII​
b) ISO-LATIN-1​
c) None of the mentioned​
d) ASCII and ISO-LATIN1​
Answer: d

5. Which one is a valid declaration of a boolean?​


a) boolean b1 = 1;​
b) boolean b2 = ‘false’;​
c) boolean b3 = false;​
d) boolean b4 = ‘true’​
Answer: c

6. Which data type value is returned by all transcendental math functions?​


a) int​
b) float​
c) double​
d) long​
Answer: c

7. What will be the output of the following Java code?


1.​ class average {
2.​ public static void main(String args[])
3.​ {
4.​ double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};
5.​ double result;
6.​ result = 0;
7.​ for (int i = 0; i < 6; ++i)
8.​ result = result + num[i];
9.​ ​ System.out.print(result/6);
10.​
11.​ }
12.​ }

a) 16.34​
b) 16.566666644​
c) 16.46666666666667​
d) 16.46666666666666​
Answer: c

8. What will be the output of the following Java code?

1.​ class output {


2.​ public static void main(String args[])
3.​ {
4.​ double a, b,c;
5.​ a = 3.0/0;
6.​ b = 0/4.0;
7.​ c=0/0.0;
8.​
9.​ ​ System.out.println(a);
10.​ System.out.println(b);
11.​ System.out.println(c);
12.​ }
13.​ }

a)

Infinity
0.0
NaN

b)

0.0
Infinity
NaN

c)

NaN
Infinity
0.0

d) none of the mentioned​


Answer: a

9. What will be the output of the following Java code?

1.​ class increment {


2.​ public static void main(String args[])
3.​ {
4.​ int g = 3;
5.​ System.out.print(++g * 8);
6.​ }
7.​ }

a) 25​
b) 24​
c) 32​
d) 33​
Answer: c

10. What will be the output of the following Java code?

1.​ class area {


2.​ public static void main(String args[])
3.​ {
4.​ double r, pi, a;
5.​ r = 9.8;
6.​ pi = 3.14;
7.​ a = pi * r * r;
8.​ System.out.println(a);
9.​ }
10.​ }

a) 301.5656​
b) 301​
c) 301.56​
d) 301.56560000​
Answer: a

11. Which of the following is not an OOPS concept in Java?​


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

12. Which of the following is a type of polymorphism in Java?​


a) Compile time polymorphism​
b) Execution time polymorphism​
c) Multiple polymorphism​
d) Multilevel polymorphism​
Answer: a

13. When does method overloading is determined?​


a) At run time​
b) At compile time​
c) At coding time​
d) At execution time​
Answer: b

14. When Overloading does not occur?​


a) More than one method with same name but different method signature and different
number or type of parameters​
b) More than one method with same name, same signature but different number of
signature​
c) More than one method with same name, same signature, same number of parameters
but different type​
d) More than one method with same name, same number of parameters and type but
different signature​
Answer: d

15. 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

16. Which concept of Java is achieved by combining methods and attribute into a class?​
a) Encapsulation​
b) Inheritance​
c) Polymorphism​
d) Abstraction​
Answer: a

17. What is it called if an object has its own lifecycle and there is no dependency?​
a) Aggregation​
b) Composition​
c) Encapsulation​
d) Association​
Answer: d
18. What is it called where a child object gets killed if the parent object is killed?​
a) Aggregation​
b) Composition​
c) Encapsulation​
d) Association​
Answer: b

19. What is it called where an object has its own lifecycle and a child object cannot
belong to another parent object?​
a) Aggregation​
b) Composition​
c) Encapsulation​
d) Association​
Answer: a

20. Method overriding is a combination of inheritance and polymorphism?​


a) True​
b) false​
Answer: a

21. Which component is used to compile, debug and execute java program?​
a) JVM​
b) JDK​
c) JIT​
d) JRE​
Answer: b

22. Which component is responsible for interpreting bytecode into machine specific
code?​
a) JVM​
b) JDK​
c) JIT​
d) JRE​
Answer: a

23. Which component is responsible for running a Java program?​


a) JVM​
b) JDK​
c) JIT​
d) JRE​
Answer: d

24. Which of the below is invalid identifier with the main method?​
a) public​
b) static​
c) private​
d) final​
Answer: c

25. What is the extension of java code files?​


a) .class​
b) .java​
c) .txt​
d) .js​
Answer: b

26. What will be the output of the following Java program?

1.​ class main_class


2.​ {
3.​ public static void main(String args[])
4.​ {
5.​ int x = 9;
6.​ if (x == 9)
7.​ {
8.​ int x = 8;
9.​ System.out.println(x);
10.​ }
11.​ }
12.​ }

a) 9​
b) 8​
c) Compilation error​
d) Runtime error​
Answer: c

27. Which of the following statements is correct?​


a) Public method is accessible to all other classes in the hierarchy​
b) Public method is accessible only to subclasses of its parent class​
c) Public method can only be called by object of its class​
d) Public method can be accessed by calling object of the public class​
Answer: a

28. What will be the output of the following Java program?

1.​ class box


2.​ {
3.​ int width;
4.​ int height;
5.​ int length;
6.​ }
7.​ class mainclass
8.​ {
9.​ public static void main(String args[])
10.​ {
11.​ box obj = new box();
12.​ obj.width = 10;
13.​ obj.height = 2;
14.​ obj.length = 10;
15.​ int y = obj.width * obj.height * obj.length;
16.​ System.out.print(y);
17.​ }
18.​ }

a) 12​
b) 200​
c) 400​
d) 100​
Answer: b

29. What will be the output of the following Java program?

1.​ class box


2.​ {
3.​ int width;
4.​ int height;
5.​ int length;
6.​ }
7.​ class mainclass
8.​ {
9.​ public static void main(String args[])
10.​ {
11.​ box obj1 = new box();
12.​ box obj2 = new box();
13.​ obj1.height = 1;
14.​ obj1.length = 2;
15.​ obj1.width = 1;
16.​ obj2 = obj1;
17.​ System.out.println(obj2.height);
18.​ }
19.​ }

a) 1​
b) 2​
c) Runtime error​
d) Garbage value​
Answer: a

30. What will be the output of the following Java program?

1.​ class box


2.​ {
3.​ int width;
4.​ int height;
5.​ int length;
6.​ }
7.​ class mainclass
8.​ {
9.​ public static void main(String args[])
10.​ {
11.​ box obj = new box();
12.​ System.out.println(obj);
13.​ }
14.​ }

a) 0​
b) 1​
c) Runtime error​
d) classname@hashcode in hexadecimal form​
Answer: d

31. What is the return type of a method that does not return any value?​
a) int​
b) float​
c) void​
d) double​
Answer: c

32. 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​
Answer: b

33. Which of the following is a method having the same name as that of its class?​
a) finalize​
b) delete​
c) class​
d) constructor​
Answer: d

34. Which method can be defined only once in a program?​


a) main method​
b) finalize method​
c) static method​
d) private method​
Answer: a

35. Which of these statements 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​
Answer: d

36. Which of these methods must be made static?​


a) main()​
b) delete()​
c) run()​
d) finalize()​
Answer: a

37. What will be the output of the following Java program?

1.​ class access


2.​ {
3.​ public int x;
4.​ ​ static int y;
5.​ void cal(int a, int b)
6.​ {
7.​ x += a ;
8.​ y += b;
9.​ }
10.​ }
11.​ class static_specifier
12.​ {
13.​ public static void main(String args[])
14.​ {
15.​ access obj1 = new access();
16.​ access obj2 = new access();
17.​ obj1.x = 0;
18.​ obj1.y = 0;
19.​ obj1.cal(1, 2);
20.​ obj2.x = 0;
21.​ obj2.cal(2, 3);
22.​ System.out.println(obj1.x + " " + obj2.y);
23.​ }
24.​ }

a) 1 2​
b) 2 3​
c) 3 2​
d) 1 5​
Answer: d

38. What will be the output of the following Java program?

1.​ class access


2.​ {
3.​ static int x;
4.​ void increment()
5.​ {
6.​ x++;
7.​ }
8.​ }
9.​ class static_use
10.​ {
11.​ public static void main(String args[])
12.​ {
13.​ access obj1 = new access();
14.​ access obj2 = new access();
15.​ obj1.x = 0;
16.​ obj1.increment();
17.​ obj2.increment();
18.​ System.out.println(obj1.x + " " + obj2.x);
19.​ }
20.​ }

a) 1 2​
b) 1 1​
c) 2 2​
d) Compilation Error​
Answer: c

39. What will be the output of the following Java program?

1.​ class static_out


2.​ {
3.​ static int x;
4.​ ​ static int y;
5.​ void add(int a , int b)
6.​ {
7.​ x = a + b;
8.​ y = x + b;
9.​ }
10.​ }
11.​ class static_use
12.​ {
13.​ public static void main(String args[])
14.​ {
15.​ static_out obj1 = new static_out();
16.​ static_out obj2 = new static_out();
17.​ int a = 2;
18.​ obj1.add(a, a + 1);
19.​ obj2.add(5, a);
20.​ System.out.println(obj1.x + " " + obj2.y);
21.​ }
22.​ }

a) 7 7​
b) 6 6​
c) 7 9​
d) 9 7​
Answer: c

40. What will be the output of the following Java program?

1.​ class Output


2.​ {
3.​ public static void main(String args[])
4.​ {
5.​ int arr[] = {1, 2, 3, 4, 5};
6.​ for ( int i = 0; i < arr.length - 2; ++i)
7.​ System.out.println(arr[i] + " ");
8.​ }
9.​ }

a) 1 2​
b) 1 2 3​
c) 1 2 3 4​
d) 1 2 3 4 5​
Answer: b

41. Which of these access specifiers must be used for main() method?​
a) private​
b) public​
c) protected​
d) none of the mentioned​
Answer: b

42. Which of these is used to access a member of class before the object of that class is
created?​
a) public​
b) private​
c) static​
d) protected​
Answer: c

43. Which of these is used as a default for a member of a class if no access specifier is
used for it?​
a) private​
b) public​
c) public, within its own package​
d) protected​
Answer: c

44. What is the process by which we can control what parts of a program can access the
members of a class?​
a) Polymorphism​
b) Abstraction​
c) Encapsulation​
d) Recursion​
Answer: c

45. Which of the following statements are incorrect?​


a) public members of class can be accessed by any code in the program​
b) private members of class can only be accessed by other members of the class​
c) private members of class can be inherited by a subclass, and become protected
members in subclass​
d) protected members of a class can be inherited by a subclass, and become private
members of the subclass​
Answer: c

46. What will be the output of the following Java program?

1.​ class recursion


2.​ {
3.​ int func (int n)
4.​ {
5.​ int result;
6.​ result = func (n - 1);
7.​ return result;
8.​ }
9.​ }
10.​ class Output
11.​ {
12.​ public static void main(String args[])
13.​ {
14.​ recursion obj = new recursion() ;
15.​ System.out.print(obj.func(12));
16.​ }
17.​ }

a) 0​
b) 1​
c) Compilation Error​
d) Runtime Error​
Answer: d

47. What will be the output of the following Java program?

1.​ class recursion


2.​ {
3.​ int func (int n)
4.​ {
5.​ int result;
6.​ if (n == 1)
7.​ return 1;
8.​ result = func (n - 1);
9.​ return result;
10.​ }
11.​ }
12.​ class Output
13.​ {
14.​ public static void main(String args[])
15.​ {
16.​ recursion obj = new recursion() ;
17.​ System.out.print(obj.func(5));
18.​ }
19.​ }
a) 0​
b) 1​
c) 120​
d) None of the mentioned​
Answer: b

48. What will be the output of the following Java program?

1.​ class recursion


2.​ {
3.​ int fact(int n)
4.​ {
5.​ int result;
6.​ if (n == 1)
7.​ return 1;
8.​ result = fact(n - 1) * n;
9.​ return result;
10.​ }
11.​ }
12.​ class Output
13.​ {
14.​ public static void main(String args[])
15.​ {
16.​ recursion obj = new recursion() ;
17.​ System.out.print(obj.fact(5));
18.​ }
19.​ }

a) 24​
b) 30​
c) 120​
d) 720​
Answer: c

49. What will be the output of the following Java program?

1.​ class recursion


2.​ {
3.​ int fact(int n)
4.​ {
5.​ int result;
6.​ if (n == 1)
7.​ return 1;
8.​ result = fact(n - 1) * n;
9.​ return result;
10.​ }
11.​ }
12.​ class Output
13.​ {
14.​ public static void main(String args[])
15.​ {
16.​ recursion obj = new recursion() ;
17.​ System.out.print(obj.fact(1));
18.​ }
19.​ }

a) 1​
b) 30​
c) 120​
d) Runtime Error​
Answer: a

50. What will be the output of the following Java program?

1.​ class recursion


2.​ {
3.​ int fact(int n)
4.​ {
5.​ int result;
6.​ if (n == 1)
7.​ return 1;
8.​ result = fact(n - 1) * n;
9.​ return result;
10.​ }
11.​ }
12.​ class Output
13.​ {
14.​ public static void main(String args[])
15.​ {
16.​ recursion obj = new recursion() ;
17.​ System.out.print(obj.fact(6));
18.​ }
19.​ }

a) 1​
b) 30​
c) 120​
d) 720​
Answer: d

51. Which of these keywords can be used in a subclass to call the constructor of
superclass?​
a) super​
b) this​
c) extent​
d) extends​
Answer: a

52. What is the process of defining a method in a subclass having the same name &
type signature as a method in its superclass?​
a) Method overloading​
b) Method overriding​
c) Method hiding​
d) None of the mentioned​
Answer: b
53. Which of these keywords can be used to prevent Method overriding?​
a) static​
b) constant​
c) protected​
d) final​
Answer: d

54. Which of these is the correct way of calling a constructor having no parameters, of
superclass A by subclass B?​
a) super(void);​
b) superclass.();​
c) super.A();​
d) super();​
Answer: d

55. At line number 2 in the following code, choose 3 valid data-type attributes/qualifiers
among “final, static, native, public, private, abstract, protected”

1.​ public interface Status


2.​ {
3.​ /* insert qualifier here */ int MY_VALUE = 10;
4.​ }

a) final, native, private​


b) final, static, protected​
c) final, private, abstract​
d) final, static, public​
Answer: d

56. Static members are not inherited to subclass.​


a) True​
b) False​
Answer: b

57. Which of the following is used for implementing inheritance through an interface?​
a) inherited​
b) using​
c) extends​
d) implements​
Answer: d

58. Which of the following is used for implementing inheritance through class?​
a) inherited​
b) using​
c) extends​
d) implements​
Answer: c

59. What would be the result if a class extends two interfaces and both have a method
with the same name and signature? Let's assume that the class is not implementing that
method.​
a) Runtime error​
b) Compile time error​
c) Code runs successfully​
d) First called method is executed successfully​
Answer: b

60. Does Java support Multilevel inheritance?​


a) True​
b) False​
Answer: a

61. Which of these keywords are used to define an abstract class?​


a) abst​
b) abstract​
c) Abstract​
d) abstract class​
Answer: b

62. Which of these is not abstract?​


a) Thread​
b) AbstractList​
c) List​
d) None of the Mentioned​
Answer: a

63. If a class inheriting an abstract class does not define all of its function then it will be
known as?​
a) Abstract​
b) A simple class​
c) Static class​
d) None of the mentioned​
Answer: a

64. Which of these is not a correct statement?​


a) Every class containing abstract method must be declared abstract​
b) Abstract class does not define the complete implementation of a class​
c) Abstract class can be initiated by new operator​
d) Abstract class can be inherited​
Answer: c
65. Which of these packages contains abstract keywords?​
a) java.lang​
b) java.util​
c) java.io​
d) java.system​
Answer: a

66. Which of these is an incorrect statement?​


a) String objects are immutable, they cannot be changed​
b) String object can point to some other reference of String variable​
c) StringBuffer class is used to store string in a buffer for later use​
d) None of the mentioned​
Answer: c

67. What will be the output of the following Java program?

1.​ class String_demo


2.​ {
3.​ public static void main(String args[])
4.​ {
5.​ char chars[] = {'a', 'b', 'c'};
6.​ String s = new String(chars);
7.​ System.out.println(s);
8.​ }
9.​ }

a) a​
b) b​
c) c​
d) abc​
Answer: d

68. What will be the output of the following Java program?

1.​ class String_demo


2.​ {
3.​ public static void main(String args[])
4.​ {
5.​ int ascii[] = { 65, 66, 67, 68};
6.​ String s = new String(ascii, 1, 3);
7.​ System.out.println(s);
8.​ }
9.​ }

a) ABC​
b) BCD​
c) CDA​
d) ABCD​
Answer: b
69. What will be the output of the following Java program?

1.​ class String_demo


2.​ {
3.​ public static void main(String args[])
4.​ {
5.​ char chars[] = {'a', 'b', 'c'};
6.​ String s = new String(chars);
7.​ String s1 = "abcd";
8.​ int len1 = s1.length();
9.​ int len2 = s.length();
10.​ System.out.println(len1 + " " + len2);
11.​ }
12.​ }

a) 3 0​
b) 0 3​
c) 3 4​
d) 4 3​
Answer: d

70. Which of these classes is the superclass of String and StringBuffer class?​
a) java.util​
b) java.lang​
c) ArrayList​
d) None of the mentioned​
Answer: b

71. Which of these methods of class String is used to compare two String objects for
their equality?​
a) equals()​
b) Equals()​
c) isequal()​
d) Isequal()​
Answer: a

72. Which of these methods is used to compare a specific region inside a string with
another specific region in another string?​
a) regionMatch()​
b) match()​
c) RegionMatches()​
d) regionMatches()​
Answer: d

73. Which of these methods of class String is used to check whether a given object
starts with a particular string literal?​
a) startsWith()​
b) endsWith()​
c) Starts()​
d) ends()​
Answer: a

74. What is the value returned by function compareTo() if the invoking string is less than
the string compared?​
a) zero​
b) value less than zero​
c) value greater than zero​
d) none of the mentioned​
Answer: b

75. Which of these data type values is returned by equals() method of String class?​
a) char​
b) int​
c) boolean​
d) all of the mentioned​
Answer: c

76. What will be the output of the following Java code?

1.​ class output


2.​ {
3.​ public static void main(String args[])
4.​ {
5.​ StringBuffer c = new StringBuffer("Hello");
6.​ System.out.println(c.length());
7.​ }
8.​ }

a) 4​
b) 5​
c) 6​
d) 7​
Answer: b

77. What will be the output of the following Java code?

1.​ class output


2.​ {
3.​ public static void main(String args[])
4.​ {
5.​ StringBuffer sb=new StringBuffer("Hello");
6.​ sb.replace(1,3,"Java");
7.​ System.out.println(sb);
8.​ }
9.​ }

a) Hello java​
b) Hellojava​
c) HJavalo​
d) Hjava​
Answer: c

78. What will be the output of the following Java code?

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​
Answer: c

79. What will be the output of the following Java code?

1.​ class output


2.​ {
3.​ public static void main(String args[])
4.​ {
5.​ StringBuffer s1 = new StringBuffer("Hello World");
6.​ s1.insert(6 , "Good ");
7.​ System.out.println(s1);
8.​ }
9.​ }

a) HelloGoodWorld​
b) HellGoodoWorld​
c) HellGood oWorld​
d) Hello Good World​
Answer: d

80. What will be the output of the following Java code?

1.​ class output


2.​ {
3.​ public static void main(String args[])
4.​ {
5.​ StringBuffer s1 = new StringBuffer("Hello");
6.​ s1.insert(1,"Java");
7.​ System.out.println(s1);
8.​ }
9.​ }
a) hello​
b) java​
c) Hello Java​
d) HJavaello​
Answer: d

81. Which of the following is not a segment of memory in java?​


a) Stack Segment​
b) Heap Segment​
c) Code Segment​
d) Register Segment​
Answer: d

82. Does code Segment load the java code?​


a) True​
b) False​
Answer: a

83. What is JVM?​


a) Bootstrap​
b) Interpreter​
c) Extension​
d) Compiler​
Answer: b

84. Which one of the following is a class loader?​


a) Bootstrap​
b) Compiler​
c) Heap​
d) Interpreter​
Answer: a

85. Which class loader loads jar files from the JDK directory?​
a) Bootstrap​
b) Extension​
c) System​
d) Heap​
Answer: a

86. Which of the following matches nonword characters using regular expressions in
java?​
a) \w​
b) \W​
c) \s​
d) \S​
Answer: b

87. Which of the following matches the end of the string using regular expression in
java?​
a) \z​
b) \\​
c) \*​
d) \Z​
Answer: a

88. What does public int end(int group) return?​


a) offset from last character of the subsequent group​
b) offset from first character of the subsequent group​
c) offset from last character matched​
d) offset from first character matched​
Answer: a

89. What does public String replaceAll(string replace) do?​


a) Replace all characters that matches pattern with a replacement string​
b) Replace first subsequence that matches pattern with a replacement string​
c) Replace all other than first subsequence of that matches pattern with a replacement
string​
d) Replace every subsequence of the input sequence that matches pattern with a
replacement string​
Answer: d

90. What does public int start() return?​


a) returns start index of the input string​
b) returns start index of the current match​
c) returns start index of the previous match​
d) none of the mentioned​
Answer: c

91. Which of these packages contains classes and interfaces for networking?​
a) java.io​
b) java.util​
c) java.net​
d) java.network​
Answer: c

92. Which of these is a protocol for breaking and sending packets to an address across
a network?​
a) TCP/IP​
b) DNS​
c) Socket​
d) Proxy Server​
Answer: a

93. How many ports of TCP/IP are reserved for specific protocols?​
a) 10​
b) 1024​
c) 2048​
d) 512​
Answer: b

94. How many bits are in a single IPv4 address?​


a) 8​
b) 16​
c) 32​
d) 64​
Answer: c

95. Which of these is a full form of DNS?​


a) Data Network Service​
b) Data Name Service​
c) Domain Network Service​
d) Domain Name Service​
Answer: d

96. What should not be done to avoid deadlock?​


a) Avoid using multiple threads​
b) Avoid hold several locks at once​
c) Execute foreign code while holding a lock​
d) Use interruptible locks​
Answer: c

97. What is true about threading?​


a) run() method calls start() method and runs the code​
b) run() method creates new thread​
c) run() method can be called directly without start() method being called​
d) start() method creates new thread and calls code written in run() method​
Answer: d

98. Which of the following is a correct constructor for thread?​


a) Thread(Runnable a, String str)​
b) Thread(int priority)​
c) Thread(Runnable a, int priority)​
d) Thread(Runnable a, ThreadGroup t)​
Answer: a
99. Which of the following stops execution of a thread?​
a) Calling SetPriority() method on a Thread object​
b) Calling notify() method on an object​
c) Calling wait() method on an object​
d) Calling read() method on an InputStream object​
Answer: b

100. Which of the following will ensure the thread will be in running state?​
a) yield()​
b) notify()​
c) wait()​
d) Thread.killThread()​
Answer: c

101. Which exception is thrown when java is out of memory?​


a) MemoryError​
b) OutOfMemoryError​
c) MemoryOutOfBoundsException​
d) MemoryFullException​
Answer: b

102. What will be the output of the following Java code?

1.​ class String_demo


2.​ {
3.​ public static void main(String args[])
4.​ {
5.​ char chars[] = {'a', 'b', 'c'};
6.​ String s = new String(chars);
7.​ System.out.println(s);
8.​ }
9.​ }

a) abc​
b) a​
c) b​
d) c​
Answer: a

103. Which of these are selection statements in Java?​


a) break​
b) continue​
c) for()​
d) if()​
Answer: d

104. What will be the output of the following Java program?


1.​ class recursion
2.​ {
3.​ int func (int n)
4.​ {
5.​ int result;
6.​ if (n == 1)
7.​ return 1;
8.​ result = func (n - 1);
9.​ return result;
10.​ }
11.​ }
12.​ class Output
13.​ {
14.​ public static void main(String args[])
15.​ {
16.​ recursion obj = new recursion() ;
17.​ System.out.print(obj.func(5));
18.​ }
19.​ }

a) 1​
b) 120​
c) 0​
d) None of the mentioned​
Answer: a

105. What will be the output of the following Java code?

1.​ class output


2.​ {
3.​ public static void main(String args[])
4.​ {
5.​ String c = "Hello i love java";
6.​ boolean var;
7.​ var = c.startsWith("hello");
8.​ System.out.println(var);
9.​ }
10.​ }

a) 0​
b) true​
c) 1​
d) false​
Answer: d

106. Which of these keywords is used to define interfaces in Java?​


a) intf​
b) Intf​
c) interface​
d) Interface​
Answer: c

107. What will be the output of the following Java program?


1.​ class output
2.​ {
3.​ public static void main(String args[])
4.​ {
5.​ StringBuffer s1 = new StringBuffer("Quiz");
6.​ StringBuffer s2 = s1.reverse();
7.​ System.out.println(s2);
8.​ }
9.​ }

a) QuizziuQ​
b) ziuQQuiz​
c) Quiz​
d) ziuQ​
Answer: d

108. What will be the output of the following Java code?

1.​ class Output


2.​ {
3.​ public static void main(String args[])
4.​ {
5.​ Integer i = new Integer(257);
6.​ byte x = i.byteValue();
7.​ System.out.print(x);
8.​ }
9.​ }

a) 257​
b) 256​
c) 1​
d) 0​
Answer: c

109. What will be the output of the following Java program?

1.​ class Output


2.​ {
3.​ public static void main(String args[])
4.​ {
5.​ double x = 2.0;
6.​ double y = 3.0;
7.​ double z = Math.pow( x, y );
8.​ System.out.print(z);
9.​ }
10.​ }

a) 9.0​
b) 8.0​
c) 4.0​
d) 2.0​
Answer: b
110. Which of the following is a superclass of every class in Java?​
a) ArrayList​
b) Abstract class​
c) Object class​
d) String​
Answer: c

You might also like