java exam 0 votes, 0 avg 223 123456789101112131415 Java Questions 1 / 15 1. Find the output of the following code. import java.util.Scanner; class ThisKeyword { private int a = 4; private int b = 1; void getSum(int a, int b) { this.a = a; this.b = b; System.out.println(this.a + this.b); } } public class Main { public static void main(String args[]) { ThisKeyword T = new ThisKeyword(); T.getSum(3, 5); } } A. 5 B. 9 C. 8 D. 4 2 / 15 2. Find the output of the following program. public class Solution{ public static void main(String[] args){ byte x = 127; x++; x++; System.out.print(x); } } A. -127 B. 2 C. 129 D. 127 3 / 15 3. How many objects will be created in the following? String a = new String(“Interviewbit”); String b = new String(“Interviewbit”); Strinc c = “Interviewbit”; String d = “Interviewbit”; A. 2 B. 3 C. 4 D. none 4 / 15 4. A method within a class is only accessible by classes that are defined within the same package as the class of the method. Which one of the following is used to enforce such restriction? A. Declare the method with the keyword protected B. Declare the method with the keyword private C. Do not declare the method with any accessibility modifiers D. Declare the method with the keyword public and private. 5 / 15 5. Find the output of the following code. class bool_operator { public static void main(String args[]) { boolean a = true; boolean b = !true; boolean c = a | b; boolean d = a & b; boolean e = d ? b : c; System.out.println(d + " " + e); } } A. true false B. false false C. true true D. false true 6 / 15 6. Which of these can be used to differentiate two or more methods having the same name? A. Parameters data type B. Number of parameters C. Return type of method D. All of the mentioned 7 / 15 7. What will be the output of the following Java code? class Output { public static void main(String args[]) { Object obj = new Object(); System.out.print(obj.getclass()); } } A. Object B. class Object C. class java.lang.Object D. Compilation Error 8 / 15 8. Which of the following are not java modifiers? A. public B. private C. friendly D. transient 9 / 15 9. Which of these statements is incorrect about Thread? A. start() method is used to begin execution of the thread B. run() method is used to begin execution of a thread before start() method in special cases C. A thread can be formed by implementing Runnable interface only D. A thread can be formed by a class that extends Thread class 10 / 15 10. How is Date stored in database? A. java.sql.Date B. java.util.Date C. java.sql.DateTime D. java.util.DateTime 11 / 15 11. What is garbage collection in the context of Java? A. The JVM checks the output of any Java program and deletes anything that doesn’t make sense B. Any package imported in a program and not used is automatically deleted. C. When all references to an object are gone the memory used by the object is not reclaimed. D. When all references to an object are gone, the memory used by the object is automatically reclaimed. 12 / 15 12. What will be the output of the following Java code? class Output { public static void main(String args[]) { Integer i = new Integer(257); byte x = i.byteValue(); System.out.print(x); } } A. 257 B. 256 C. 1 D. O 13 / 15 13. Find the output of the following code. class overload { int x; double y; void add(int a , int b) { x = a + b; } void add(double c , double d) { y = c + d; } overload() { this.x = 0; this.y = 0; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int a = 2; double b = 3.2; obj.add(a, a); obj.add(b, b); System.out.println(obj.x + " " + obj.y); } } A. 4 6.4 B. 6.4 6 C. 6.4 6.4 D. 6 6 14 / 15 14. Find the output of the following program. public class Solution{ public static void main(String[] args){ short x = 10; x = x * 5; System.out.print(x); } } A. Compilation error B. 50 C. 10 D. Exception 15 / 15 15. 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 Your score is The average score is 35% LinkedIn Facebook Twitter VKontakte 0% Restart quiz