1. What will be the output of the following code snippet?
int x=5, y=1;
if(x++>5)
{
if(y<2) System.out.println("Hi");
else System.out.println("Bye");
}
else System.out.println("Oh");
A. Hi B. Bye C. Oh D. Compilation Error
Ans: C
2. What will be the output of the following code snippet?
if(!true) System.out.print("Hi ");
if(true) System.out.print("Hello ");
else System.out.println("Bye");
A. Hi Bye B. Hello C. Bye D. Compilation Error
Ans: B
3. Which of the following is INCORRECT header for the main method in java?
A. public static void main(String [] arg)
B. static public void main(String arg [])
C. public static void main(String...arg)
D. None of These
Ans: D
4. Which of the following is NOT a feature of Java?
A. secure B. platform-dependent
C. robust D. multi-threaded
Ans: B
5. Which of the following Java Edition is dedicated for Web-application development?
A. Java SE
B. Java EE
C. Java ME
D. JavaFX
Ans: B
6. Which of the following statement is TRUE about the following class?
class A{}
A. It can be saved in a file named as B.java and compiled using command javac B.java
B. It can be saved only with name A.java and compiled using command javac A.java
C. It can not be instantiated.
D. None of These
Ans: A
7. Which of the following statement is TRUE about the following class?
class A{}
A. Class will not compile
B. Class will compile but can not be executed directly.
C. Instance of A CAN NOT be created.
D. Both B & C
Ans: B
8. Which of the following statement(s) is/are correct?
A. Java is portable and platform-dependent.
B. Java was invented by James Gosling.
C. Java uses Interpreter for execution of program.
D. Both B & C.
Ans: D
9. Which of the following is full form of "JDK" and "JVM"?
A. Java Deployment Kit, Java Virtual Mail
B. Java Distribution Kit, Java Virtual Machine
C. Java Development Kit, Java Vital Machine
D. None of These
Ans: D
10. Which of the following is CORRECT char variable declaration?
A. char c = (int)65.1;
B. char c = a;
C. char c = '11';
D. None of These;
Ans: A
11. In order for a java source code file, containing the public class Test, to successfully compile, which of the following must be true?
A. It must have only one class in it.
B. It must be named Test.java.
C. It must import java.lang package.
D. Both A & B
Ans: B
12. The following class is saved in a file named as Hello.java. Which of the following is TRUE about it?
public class A{}
A. It can be compiled using command javac A.java
B. It will be compiled using command javac A.java
C. It must be saved in a file named as A.java, otherwise it will not compile.
D. None of These
Ans: C
13. All the tools like javac. java etc available in _____.
A. java --> jdk --> bin
B. java --> jre --> bin
C. java --> jdk --> jre --> bin
D. java --> jdk --> tools --> bin
Ans: A
14. All the objects in Java are created inside ______ and local variable in ______.
A. Class Area, Heap
B. Heap, Class Area
C. Heap, Stack
D. Class Area, Stack
Ans: C
15. Which of the following is the minimum requirement for executing a java Program?
A. JDK B. JVM
C. JRE D. Both JDK and JRE
Ans: C
16. Which of the following keyword is used to restrict the accessibility of a method within the enclosing class?
A. private B. static
C. final D. None of These
Ans: A
17. Which of the following keyword is used to declare a class variable in Java?
A. private B. final
C. static D. default
Ans: C
18. What will be the output of the following code snippet? int x=10, y=5;
x = --y + x-- - --x + y;
System.out.println(x);
A. 10 B. 9 C. 11 D. 14
Ans: A
19. Which of the following keywords are NOT allowed with local variables in Java?
i. private ii. static iii. final
A. only i B. i & ii C. i & iii D. All
Ans: B
20. What will be the output of the following statement? System.out.println( 3>4 || 4>3 ? false : true);
A. true B. false
C. falsetruefalse D. Compilation Error
Ans: B
21. What will be the output of the following statement?
byte b = 37;
System.out.println(~b);
A. -38 B. -37
C. -36 D. Compilation Error
Ans: A
22. Which of the following keyword is reserved but not used in Java?
A. const B. goto C. default D. Both A & B
Ans: D
23. Which of the following is a valid variable declaration?
A. byte b = 200;
B. float f = 10.20;
C. boolean b = true;
D. char c = '65';
Ans: C
24. Which of the following is an invaild array declaration?
A. int ... arr;
B. char ch [] = {A, B, C, D, E};
C. boolean [] b = {false, true, true};
D. Object ob [] = new Object[10];
Ans: B
25. What is the size of char type variable in Java?
A. 8 bits
B. 16 bits
C. 32 bits
D. Not Defined
Ans: B
26. In order for a java source code file, containing the public class Test, to successfully compile, which of the following must be true?
A. It must have only one class in it.
B. It must be named Test.java.
C. It must import java.lang package.
D. Both A & B
Ans: B
27. What will be the output of the following statement?
System.out.println(-112>>3);
A. -13 B. -14 C. 13 D. 14
Ans: B
28. What will be the output of the following code snippet?
int i=10, j=5;
while(--i>10 && ++j>5);
System.out.println(i+””+j);
A. 96 B. 105
C. 95 D. Compilation Error
Ans: C
29. What will be the output of the following code:
int i= 5, j=2;
for( ; i-- > ++j ; )
System.out.println(i+””+j);
A. 43 B. 53
C. 34 D. Compilation Error
Ans: A
30. Which of the following will print 7?
A. System.out.println(29 >> 2);
B. System.out.println(59 >>> 3);
C. byte b = -8; System.out.println(~b);
D. All the Above
Ans: D
31. Which of the following statement will result in compilation error?
A. boolean b = 4>3 & 5<2;
B. -43>>>2;
C. boolean b = 0;
D. None of These
Ans: C
32. Which of the following is NOT a unary operator?
A. ! B. &
C. + D. Both B & C
Ans: B
33. What will be the output of the following code snippet? int x=10, y=5;
x = --y + x-- - --x + y;
System.out.println(x);
A. 10 B. 9
C. 11 D. 14
Ans: A
34. If class Y is a subclass of X, Which of the following statement will return true?
X x1 = new Y();
A. x1 != null; B. x1 instanceof Y
C. Both A & B D. None of These
Ans: C
35. What will be the output of the following code snippet?
StringBuilder sb = new StringBuilder("Hi");
System.out.println(sb.capacity());
A. 2 B. 18 C. 16 D. None of These
Ans: B
36. What will be the output of the following code snippet?
String str = "Lovely";
System.out.println(str.charAt(5));
A. l B. y
C. Compilation Error D. Run-time Error
Ans: B
37. What will be the output of the following code snippet?
ArrayList al = new ArrayList(2);
al.set(1, "Hello");
System.out.println(al);
A. [ , Hello]
B. [Hello]
C. Compilation Error
D. Run-time Error
Ans: D
38. Which of the following statement will delete the the third element of an ArrayList al containing 5 elements?
A. al.delete(3); B. al.remove(3);
C. al.delete(2); D. al.remove(2);
Ans: D
39. What will be the output of the following code snippet?
ArrayList al = new ArrayList();
al.add("A"); al.add("B"); al.add("C");
ArrayList al2 = new ArrayList();
al2.add("Hi");
System.out.println(al2.add(al));
A. [Hi, [A, B, C]]
B. [Hi, A, B, C]
C. true
D. Compilation Error
Ans: C
40. LocalDate class is defined in ____ package.
A. java.date B. java.time
C. java.util.date D. java.util.time
Ans: B
41. Which Exception will be thrown by the Following code snippet?
LocalDate ld=LocalDate.of(2016,Month.FEBRUARY,30);
A. java.time.DateTimeException
B. java.time.TimeDateException
C. java.time.TimeException
D. java.time.format.DateTimeParseException
Ans: A
42. Which of the following can be correct output of the given code snippet?
LocalTime lt=LocalTime.now();
System.out.println(lt);
A. 09:40:09.121NS
B. 09:40:09.121000000
C. 09:40:09.121S
D. 09:40:09.121
Ans: D
43. What will be the output of following code snippet?
LocalTime lt=LocalTime.of(12,20,15,345);
System.out.println(lt);
A. 12:20:15.345
B. 12:20:15.345S
C. 12:20:15.000000345
D. Exception
Ans: C
44. Which of the following method of String class is most appropriate for extracting all the characters of String into an array?
A. charAt() B. toCharArray()
C. getChar() D. getChars()
Ans: B
45. String s = "Hello World";
Which of the following statement will print "World"?
A. System.out.println(s.substring(6, 11));
B. System.out.println(s.substring(6, 10));
C. System.out.println(s.substring(7, 11));
D. System.out.println(s.substring(6, 10));
Ans: A
46. What will be the output of the following code snippet?
StringBuilder b = new StringBuilder("Welcome");
System.out.println(b.delete(3, 5));
A. Weme B. Wele
C. Welme D. None of These
Ans: C
47. What will be the output of the following code snippet?
String s = "This is an island";
System.out.println(s.lastIndexOf("is"));
A. 11 B. 12
C. 2 D. None of These
Ans: A
48. Which of the following is/are TRUE about Constructor?
A. Constructors can be declared private.
B. Constructors can be overloaded.
C. Constructors can be declared static.
D. Both A & B
Ans: D
49. Which of the following is FALSE about final keyword?
A. A Final class can not be inherited.
B. A final method can not be overloaded.
C. Value of a final variable can not be changed.
D. None of These
Ans: B
50. In java, _____ can only test for equality, where as ____ can evaluate any type of boolean expression.
A. switch, if
B. if, switch
C. switch, break
D. if, else
Ans: A
51. Which of these statement is INCORRECT?
A. switch statement is more efficient than a set of nested ifs.
B. Two case constants in the same switch can have identical values.
C. switch statement can only test for equality, whereas if statement can evaluate any type of boolean expression.
D. It is possible to create a nested switch statements.
Ans: B
52. Which of these jump statements can skip processing remainder of code in its body for a particular iteration?
A. break B. return
C. continue D. None of These
Ans: C
53. Which of the following can be the return type of a constructors?
A. int B. float
C. void D. None
Ans: D
54. Which of the following is FALSE about Constructor?
A. It is having same name as the name of the class.
B. It is having void return type.
C. It can not have return statement inside it.
D. Constructors can be overloaded.
Ans: B
55. What will be the output of the following code?
class Test
{
int x=10;
Test(int a)
{
System.out.print(x);
x=a;
}
public static void main(String [] arg)
{
new Test(5);
}
}
A. 0 B. 5 C. 10 D. Compilation Error
Ans: C
56. What will be the output of the following Program?
class Test
{
Test(int a)
{
System.out.print("Hi");
}
public static void main(String [] arg)
{
Test t = new Test();
}
}
A. No Output B. Hi
C. Compilation Error D. None of These
Ans: C
57. Which of the following is FALSE about Abstract class?
A. Abstract class can not inherit another abstract class.
B. Abstract class can have constructors.
C. Abstract class can not be declared private.
D. Abstract class can contain non-abstract methods.
Ans: A
58. Defining two or more methods with same name but different signature is known as ______.
A. Method Overriding B. Method Overloading
C. Method Hiding D. None of These
Ans: B
59. Redefining the super class method in the subclass is known as ______.
A. Method Overriding B. Method Overloading
C. Dynamic Binding D. None of These
Ans: A
60. Which of the following is FALSE about final keyword in Java?
A. It is used to prevent the inheritance of a class.
B. It is used to declare the constant in Java.
C. Local variables can not be declared final.
D. Abstract class can not be declared final.
Ans: C
61. final keyword can not be used with ____.
A. method B. class
C. local variable D. constructor
Ans: D
62. Which of the following keyword is NOT allowed with Constructor?
i. final ii. static iii. private
A. ii & iii B. i & ii
C. Only ii D. i, ii & iii
ANs: B
63. Which of the following is Incorrect?
A. Method overloading can be done in sub-class also.
B. Two methods with same signature but different return type are overloaded.
C. Static methods can't be overloaded.
D. Both B & C
Ans: B
64. What will be the output of the following program?
class Demo
{
public void demo(byte b)
{
System.out.print("Byte");
}
public static void demo( long l)
{
System.out.print("Long");
}
public static void main(String [] arg)
{
new Demo().demo(1);
}
}
A. Byte B. Long
C. Compilation Error D. None of these
Ans: B
65. Which of the following keyword must be used to inherit a class?
A. super B. implements
C. extend D. extends
Ans: D
66. Which of these keywords is used to refer to member of base class from a sub class?
A. static B. final
C. this D. super
Ans: D
67. Which of the following is FALSE about abstract class?
A. Any class which is qualified with abstract keyword is an abstract class.
B. Abstract class is a class which can not be inherited.
C. An abstract class is class which cannot be instantiated.
D. None of These
Ans: B
68. Can an abstract class define both abstract methods and non-abstract methods?
A. No--it must have all abstract or all non-abstract.
B. No--it must have all abstract methods.
C. Yes--but the child classes do not inherit the abstract methods.
D. Yes--and the child classes inherit both.
Ans: D
69. Can an abstract parent class have non-abstract children?
A. No--an abstract parent must have only abstract children.
B. No--an abstract parent must have no children at all.
C. Yes--all children of an abstract parent must be non-abstract.
D. Yes--an abstract parent can have both abstract and non-abstract children.
Ans: D
70. Can an object of a child type be assigned to a variable of the parent type?
A. Yes--an object can be assigned to a reference variable of the parent type.
B. Yes--any object can be assigned to any reference variable.
C. No--there must always be an exact match between the variable and the object types.
D. No--but an object of parent type can be assigned to a variable of child type.
Ans: A
71. class A{}
class B extends A{}
Given, A a1 = new B();
What will be the output of the following statement?
System.out.println(a1 instanceof B);
A. true B. false
C. Compilation Error D. Runtime Error
Ans: A
72. What will be the output of the following Program?
class A
{
void test(){System.out.println("In A");}
}
class B extends A
{
public void test(){System.out.println("In B");}
}
class Test
{
public static void main(String [] arg)
{
A a1 = new B();
a1.test();
}
}
A. In A B. Compilation Error
C. In B D. Runtime Error
Ans: C
73. What will be the output of the following Program?
class A
{
static void test(){System.out.print("In A");}
}
class B extends A
{
public static void test(){System.out.print("In B");}
}
class Test
{
public static void main(String [] arg)
{
A a1 = new B();
a1.test();
}
}
A. In A B. Compilation Error
C. In B D. Runtime Error
Ans: A
74. Which of the following is correct about the following method?
protected void demo(){}
A. It can be invoked from any class in any package.
B. It can be accessed outside the package also but only by the subclass.
C. It can be accessed only within the same package.
D. It can not be accessed outside the class.
Ans: B
75. What will be the output of the following Program?
class A{
A(int x)
{System.out.print("Hi ");}
}
class B extends A{
B(int x)
{System.out.print("Hello");}
public static void main(String [] r)
{
B b1 = new B(1);
}
}
A. Hello B. Hi Hello
C. Hi D. Compilation Error
Ans: D
76. Singleton Design pattern is used ___.
A. To ensure that the inheritance of the class is prevented.
B. To ensure that only one instance of the class can be created.
C. To ensure that all the abstract methods are implemented by the subclass.
D. Both A and B
Ans: B
77. Which of the following is FALSE about the Singleton Class?
A. It provides the private constructor only.
B. It provides a static factory method to return the instance of the class.
C. It provides a public static reference of the same class type.
D. None of These
Ans: C
78. What will be the output of the following Program?
class Test
{
void demo(int...a)
{
System.out.println("Hi");
}
void demo(int a, long b)
{
System.out.println("Hello");
}
public static void main(String [] ar)
{
new Test().demo(3, 4);
}
}
A. Hi B. Hello
C. Compilation Error D. Runtime Error
Ans: B
79. We can use these features of an abstract class even without inheriting it.
A. all the public static and non static members
B. all the public static members
C. all the public non static members
D. none of the above
Ans: B
80. Which of the following line(s) will result in compilation error?
abstract class A
{
abstract void show();
abstract void show1(){System.out.print("Test");} //Line 1
}
class B extends A
{
public void show() //Line 2
{
System.out.println("Show");
}
public static void main(String [] arg)
{
A a1 = new B(); //Line 3
a1.show();
}
}
A. Compilation Error in Line 1: abstract keyword should not be used.
B. Compilation Error in Line 2: public keyword should not be used.
C. Compilation Error in Line 3: Reference of class A can not be used.
D. Both A & B
Ans: A
This comment has been removed by the author.
ReplyDeleteThanks a lot Sir.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThanks for sharing such a good information with us.Hawkscode is a one of the bestIT service provider
ReplyDeleteLooking very good blog. I am so thankful to you and expecting more info on Core Java and please do keep sharing on...
ReplyDeleteThank you so much
Nice post. I got so many valuable information. keep sharing.
ReplyDeleteJoin project basedJava Course in Noida
Nice tutorial. Thanks for sharing the valuable info about Core java Training. it’s really helpful. Keep sharing on updated tutorials…..
ReplyDeleteThank you sir!
ReplyDeleteI am so happy after read your blog. It’s very useful blog for us.
ReplyDeletePython Corporate training in Tanzania
Good Post! Thank you so much for sharing the post, it was so good to read and useful to improve
ReplyDeleteJava Training in Electronic City
Awesome..You have clearly explained …Its very useful for me to know about new things..Keep on blogging..
ReplyDeleteArtificial Intelligence Online Training
Java Online Training
AWS Online Training
Machine Learning Online Training
Data Science Online Training
DevOps Online Training
I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously
ReplyDeletein their life, he/she can earn his living by doing blogging.Thank you for this article.
top java online training
Hello.
ReplyDeleteAre you looking for an amazing logo design for your business with 50% off I expect You will be impressed with us.Logo Designers