JAVA MULTIPLE CHOICE QUESTION Check your Knowledge Press

  • Slides: 53
Download presentation
JAVA MULTIPLE CHOICE QUESTION

JAVA MULTIPLE CHOICE QUESTION

Check your Knowledge Press to Start www. prolearninghub. com

Check your Knowledge Press to Start www. prolearninghub. com

1. Which interface provides the capability to store objects using a key-value pair? Java.

1. Which interface provides the capability to store objects using a key-value pair? Java. util. Map Java. util. Set Java. util. List Java. util. Collection www. prolearninghub. com

2. Which one is not a correct declaration of a class? final public class

2. Which one is not a correct declaration of a class? final public class Test {} class $Test{} static class Test {} public abstract class _Test {} www. prolearninghub. com

3. How can such a restriction be enforced? A method within a class is

3. How can such a restriction be enforced? A method within a class is only accessible by classes that are defined within the same package as the class of the Declare the method with the keyword public Declare the method with keyword private Declare the method with keyword protected Without any accessibility specifiers. www. prolearninghub. com

4. The name of the method used to initialize a class object? Abstract method

4. The name of the method used to initialize a class object? Abstract method Static method Constructor Overloaded method www. prolearninghub. com

5. What should be met for two methods to be overloaded? condition Same name

5. What should be met for two methods to be overloaded? condition Same name and same number of parameter but different return type. They have same name. They have different name but same number of argument. Have same name but different parameters. www. prolearninghub. com

6. Which statement does not create an object of class Student {}? new Student();

6. Which statement does not create an object of class Student {}? new Student(); Student s 1 = new Student(), s 2 = new Student(); Student s 1; Student ss = new Student s 1; t(); www. prolearninghub. com

7. ____ is used to refer a current class object Public This Static None

7. ____ is used to refer a current class object Public This Static None of these www. prolearninghub. com

8. Garbage Collection in java is done by whom? Java compiler Object class JVM

8. Garbage Collection in java is done by whom? Java compiler Object class JVM System class www. prolearninghub. com

9. const int x = 10; Is this statement is correct declaration of constant

9. const int x = 10; Is this statement is correct declaration of constant in java. NO Yes www. prolearninghub. com

10. Can you make constructor final? Yes No www. prolearninghub. com

10. Can you make constructor final? Yes No www. prolearninghub. com

11. Given the following code, which line will generate an error? class Test {

11. Given the following code, which line will generate an error? class Test { static int x = 100; // line 3 int y = 200; // line 4 public static void main(String []args) { final int z; // line 7 z = x + y; // line 8 System. out. println(z); } } Line 3 Line 7 Line 4 Line 8 www. prolearninghub. com

12. What is the most restrictive access modifier that will allow members of one

12. What is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package? Public Abstract Protected Default access www. prolearninghub. com

13. Which of the following is/are legal method declarations? Protected abstract void m 1();

13. Which of the following is/are legal method declarations? Protected abstract void m 1(); static final void m 1(){}; synchronized public final void m 1() {} Private native void m 1() www. prolearninghub. com

14. String is a Java? Class Object Variable Character array www. prolearninghub. com

14. String is a Java? Class Object Variable Character array www. prolearninghub. com

15. Which of this method of String class is used to obtain character at

15. Which of this method of String class is used to obtain character at specified index? char() Charat() char. At() www. prolearninghub. com

16. isequal() is used to: equalize two strings concat two strings count no of

16. isequal() is used to: equalize two strings concat two strings count no of characters none of above www. prolearninghub. com

17. String object can create: (Choose all that apply) 1) 2) 3) 4) by

17. String object can create: (Choose all that apply) 1) 2) 3) 4) by string literal by new keyword by final keyword none of mentioned 3; 2 1; 2 3; 4 2; 4 www. prolearninghub. com

18. What will be the output for this program? java, string, example public class

18. What will be the output for this program? java, string, example public class String. Example{ public static void main(String args[]){ String s 1="java"; char ch[]={'s', 't', 'r', 'i', 'n', 'g', 's'}; String s 2=new String(ch); String s 3=new String("example"); System. out. println(s 1); System. out. println(s 2); System. out. println(s 3); }} string, example, java, string , java, example www. prolearninghub. com

19. The method used to return char value for a particular index is: length()

19. The method used to return char value for a particular index is: length() substring() char. At() contains() www. prolearninghub. com

20. The method used to return string length: length() substring() char. At() www. prolearninghub.

20. The method used to return string length: length() substring() char. At() www. prolearninghub. com

21. The method used to return formatted length: length() join() format() isemptxy() www. prolearninghub.

21. The method used to return formatted length: length() join() format() isemptxy() www. prolearninghub. com

22. Immutable object is a object that cannot be changes when it is created?

22. Immutable object is a object that cannot be changes when it is created? Yes No www. prolearninghub. com

23. The memory which store string object is known as? Heap Stack String constant

23. The memory which store string object is known as? Heap Stack String constant pool Method area www. prolearninghub. com

import my. Library. *; public class Show. Some. Class { // code for the

import my. Library. *; public class Show. Some. Class { // code for the class. . . } 24. What is the name of the java file containing this program? my. Library. java Show. Some. Class. class www. prolearninghub. com

25. Consider the following code snippet String river = new String(‘ USA ’); System.

25. Consider the following code snippet String river = new String(‘ USA ’); System. out. println (river. length()); What is printed? 2 3 4 5 www. prolearninghub. com

26. If s = “This is java” what will be returned by s. length()

26. If s = “This is java” what will be returned by s. length() function? 9 10 11 12 www. prolearninghub. com

27. What is the difference between a Text. Area and a Text. Field? A

27. What is the difference between a Text. Area and a Text. Field? A Text. Area can handle multiple lines of text A Text. Area can be used for output Text. Area is not a class Text. Areas are used for displaying graphics www. prolearninghub. com

28. What keyword is sued to define a package? Package Void package New package

28. What keyword is sued to define a package? Package Void package New package None of mentioned www. prolearninghub. com

29. ____ is a multi-way branch statement? Switch Continue Break Label www. prolearninghub. com

29. ____ is a multi-way branch statement? Switch Continue Break Label www. prolearninghub. com

30. integer. set. Double (2. 0*5. 5+3. 2). What datatype integer has? Text field

30. integer. set. Double (2. 0*5. 5+3. 2). What datatype integer has? Text field Double field Int field double www. prolearninghub. com

31. What do you mean by a compound statement? A collection of one or

31. What do you mean by a compound statement? A collection of one or more statements enclosed in braces A statement involving if and else A way of declaring variables A way of setting the value of a variable www. prolearninghub. com

32. What will be the result of this code? String str = "Study. Tonight";

32. What will be the result of this code? String str = "Study. Tonight"; str. concat(". com"); s tr = str. to. Upper. Case(); str. replace("TONIGHT", "today"); System. out. println(str) STUDYTONIGHT STUDYtoday. com STUDYTONIGHT. COM STUDYtoday www. prolearninghub. com

33. String str = new String (“hello world”); How many object this code will

33. String str = new String (“hello world”); How many object this code will create? 0 2 1 3 www. prolearninghub. com

34. Which method is used to convert a primitive type into String? value. Of

34. Which method is used to convert a primitive type into String? value. Of () to. String() to. Char() None of above www. prolearninghub. com

35. Trim function is used? To count spaces To add spaces None of the

35. Trim function is used? To count spaces To add spaces None of the mentioned www. prolearninghub. com

36. What will be the output for this code? String str = "java is

36. What will be the output for this code? String str = "java is a object oriented language"; System. out. println(str. substring(1 6)); Java is a Object oriented language Language www. prolearninghub. com

37. What will happen if you try to compile and run the following code?

37. What will happen if you try to compile and run the following code? public class My. Class { public static void main(String arguments[]) { } public void amethod(String[] arguments) Error can’t make static reference to void method. Error method main not correct Error array must include parameter A method must be declared with String www. prolearninghub. com

38. What will be the output for this code? String str = "Java developer";

38. What will be the output for this code? String str = "Java developer"; String. Buffer sb = new String. Buffer(); for(int i=0; i < str. length(); i++) sb. append(str. char. At(i)); System. out. println(sb); It will not print anything It will print java It will print Java developer Error www. prolearninghub. com

39. What will be the output for this code? class Testimmutablestring{ public static void

39. What will be the output for this code? class Testimmutablestring{ public static void main(String args[]){ String s="Bill"; s. concat(" Clinton"); System. out. println(s); Bill Clinton Bil clin Bill Clinton www. prolearninghub. com

40. What will be the output for this code? class Testimmutablestring 1{ public static

40. What will be the output for this code? class Testimmutablestring 1{ public static void main(String args[]){ String s="Bill"; s=s. concat(" Clinton"); System. out. println(s); Bill Clinton None of mentioned www. prolearninghub. com

41. = = operator is used: To equalize To concatenation To truncate None of

41. = = operator is used: To equalize To concatenation To truncate None of these www. prolearninghub. com

42. What will be the output for this program? class Test{ public static void

42. What will be the output for this program? class Test{ public static void main(String args[]){ String a="Obama"; String b="Obama"; String c="Halary"; System. out. println(a. compare. To(b)); System. out. println(a. compare. To(c)); System. out. println(c. compare. To(a)); 0 1 1 0 -1 1 0 0 0 1 1 1 www. prolearninghub. com

43. What is the base class for all exception? java. lang. Exception java. lang.

43. What is the base class for all exception? java. lang. Exception java. lang. Throwable java. lang. Divide. By. Zero. Excep tion java. lang. Arithmetic. Exceptio n www. prolearninghub. com

44. Which type of exception will be thrown when you run this code? int

44. Which type of exception will be thrown when you run this code? int a = 100, b = 0; int c = a/b; java. lang. Exception java. lang. Throwable java. lang. Divide. By. Zero. Excep tion java. lang. Arithmetic. Exceptio n www. prolearninghub. com

45. What will happen when an exception occurs inside your code? Program will terminate

45. What will happen when an exception occurs inside your code? Program will terminate without showing any result. Program will terminate showing any error message. Java will provide a default exception handler, which will print the exception details on the terminal. System crashes. www. prolearninghub. com

46. There are _____ types of exceptions? 3 4 6 5 www. prolearninghub. com

46. There are _____ types of exceptions? 3 4 6 5 www. prolearninghub. com

47. Null pointer exception is _____ exception? Checked Unchecked Error None of these www.

47. Null pointer exception is _____ exception? Checked Unchecked Error None of these www. prolearninghub. com

48. IO exception is _____? Checked exception Unchecked exception Error None of mentioned www.

48. IO exception is _____? Checked exception Unchecked exception Error None of mentioned www. prolearninghub. com

49. What should replace XXXX ? class My. Exception extends Exception { public void

49. What should replace XXXX ? class My. Exception extends Exception { public void method() throws XXXX { throw new My. Exception(); Error My exception Runtime exception Throws clause isn’t required www. prolearninghub. com

50. Which of the following is not a valid way to create String object?

50. Which of the following is not a valid way to create String object? String str 2 = new String(new char[]{'a', 'b', 'c'}); String str = new String("abc"); String str 1 = "abc"; String str 3 = 'a'+'b'+'c'; www. prolearninghub. com

The Results

The Results