Core Java Exam Questions and Answers
Core Java Exam Questions and Answers
public class K
{
public static void main(String args[]) throws
IOException,ClassNotFoundException
{
TransientWriter tw=new TransientWriter();
ObjectOutputStream out=new ObjectOutputStream(new
FileOutputStream("[Link]"));
[Link](tw);
ObjectInputStream in=new ObjectInputStream(new
FileInputStream("[Link]"));
TransientWriter tw2=(TransientWriter)[Link]();
[Link](tw2);
}
};
Attempting to compile and run the above code
1. will cause a compiler error due to the attempt to write a transient
object.
2. will cause a runtime exception when an attempt is made to write a
transient object.
3. will not cause any runtime error and the transient object is written to
the file named "[Link]".
4. will not cause any runtime error and the transient object is not written
to the file named "[Link]".The program prints ablank line on the screen.
Correct Answer : 3
Your Answer :
QuestionID : 9453 Subject Name Core Java
Q27. Which of the following true,select the three correct answer.
1. A static method mat be invoked before even a single instance of the
class is constucted.
2. A static method cannot access non-static method of the class.
3. Abstact modifier can apper before a class or a methode but not before a
veriable
4. Final modifier can apper before a class or a veriable but not before a
methode.
Correct Answer : 1
Your Answer :
QuestionID : 9472 Subject Name Core Java
Q28. Which statement is true about a method ?
1. A method is an implementation of an abstraction
2. A method is an attribute difining the properties of particular abstraction
3. A method is a catogery of object
4. A method is an operation defining the behaviour for a particular
abstraction.
Correct Answer : 4
Your Answer :
QuestionID : 9481 Subject Name Core Java
Q29. Which method is used to determine the class of an object?
1. getClass()
2. getObject()
3. instanceOf()
4. forName()
Correct Answer : 1
Your Answer :
QuestionID : 9490 Subject Name Core Java
Q30. What, if anything , is wrong with the following code ?
}
public int addme(int x, int y,int z)
{
return this.x+x+y+this.y+this.z;
}
public int addme(mc mcc)
{
return addme(mcc.x,mcc.y,mcc.z);
}
public int addme(int x, int y)
{
return this.x+x+y+this.y;
}
}
public class test
{
public static void main(String[] args)
{
mc mcc=new mc(10,20,30);
mp mpp=new mp(10,20);
int x=[Link](10,20,30);
int y=[Link](mcc);
int z=[Link](mpp);
[Link]("Hello World!"+(x+y+z));
}
}
1. 300
2. 240
3. 120
4. compile time error
Correct Answer : 2
Your Answer :
QuestionID : 9537 Subject Name Core Java
Q34. Given the following code within a method, which statement is true?
int a,b;
b=5;
1. a & b
2. c & d both
3. a,d,e
4. c only
Correct Answer : 4
Your Answer :
QuestionID : 9538 Subject Name Core Java
Q35. The class [Link] _________ .
i. is public
ii. extends Throwable.
iii. Implemets Throwable.
iv. is Serializable.
1. i,iii,iv.
2. i,ii.
3. i,ii,iv.
4. i,iii.
Correct Answer : 3
Your Answer :
QuestionID : 9545 Subject Name Core Java
Q36. Name the Collection interface implemented by the hash table class
1. Map
2. Hash Map
3. List
4. Set
Correct Answer : 1
Your Answer :
QuestionID : 9553 Subject Name Core Java
Q37. In which of these variable declarataions will be the variable remain
uninitialised unless explicitely initialised
1. Declaration of instance variable of type int.
2. Declaration of static variable of type float.
3. Declaration of local variable of type float.
4. Declaration of static variable of type object.
Correct Answer : 3
Your Answer :
QuestionID : 9562 Subject Name Core Java
Q38. What will be the result of executing the following code?
boolean a=true;
boolean b=true;
boolean c=true;
if(a==true)
if(a==true)
if(b == true)
if(c==true)
[Link]("Some things are true in this world");
else
[Link]("Nothings is true in this world");
else if(a && (b==c))
[Link]("Its too confusing to tell what is true and what is false");
else
[Link]("Hey this wont compile");
1. The code wont compile
2. "Some things are true in this world" will be printed
3. "Hey this wont compile" will be printed
4. None
Correct Answer : 2
Your Answer :
QuestionID : 9564 Subject Name Core Java
Q39. Is this a complete and legal comment?
/* // */
1. No the block comment(/*...*/) is not ended since the single-line
comments(//...)comments out the closing part.
2. It is completely valid [Link] // part is ignored by the compiler.
3. This is combination of comments is illegal and the compiler will reject
it.
4. None of above
Correct Answer : 2
Your Answer :
QuestionID : 9586 Subject Name Core Java
Q40. Which of these are valid declarations of the main() method in order to
start the execution
of a java application?
int meth1(int i)
{
[Link](i);
return 0;
}
public static void main(String[] args)
{
[Link]([Link]());
int i=0;
i=i++ + meth1(i);
[Link](i);
}
1. prints jvm main thread name,class1,1,0.
2. prints null,name,class1,1,0.
3. program compiles successfully and give the thread name .
4. none of above.
Correct Answer : 4
Your Answer :
QuestionID : 9602 Subject Name Core Java
Q43. which of the following syntax for suggesting that the JVM performs
garbage collection:
1. [Link]();
2. [Link]();
3. [Link]();
4. [Link]();
Correct Answer : 4
Your Answer :
QuestionID : 9641 Subject Name Core Java
Q44. which of he following is illegal identifier
1. number
2. $$_100
3. all@hands
4. Number
Correct Answer : 3
Your Answer :
QuestionID : 9649 Subject Name Core Java
Q45. which will following expression evaluted using floating-point
arithematic
select one answer
1. 2.0*3.0
2. 2*3
3. 2/3 + 5/7
4. 4*5
Correct Answer : 1
Your Answer :
QuestionID : 9668 Subject Name Core Java
Q46. Which of the following are legal identifier names in Java.
1. %abcd
2. 1abcd
3. _ab_cd
4. *abcd
Correct Answer : 3
Your Answer :
QuestionID : 9676 Subject Name Core Java
Q47. which stetement would couse a compliation error if inserted in the local
indicated in the following program
public class parameterUse{
static void main(String[] args){
int a=0;
final int b=1;
int[] c={2};
final int[] d={3};
useArgs(a,b,c,d);
}
static void useArgs(final int a,int b,final int[] c,int[] d){
//Inser statement here,
}}
1. b=a;
2. d[0]++;
3. b++;
4. c=d;
Correct Answer : 4
Your Answer :
QuestionID : 9694 Subject Name Core Java
Q48. class AA{}
class BB extends AA{}
class Q6
{
public static void main(String[] args)
{
AA a=null;
BB b=(BB)a;
[Link](b);
[Link](b instanceof BB);
[Link](b instanceof AA);
}
}
1. program compiles correctly and print null,true,false.
2. program compiles correctly and print null,false,false.
3. compile time error at line no.8 as null value cannot be casted
4. run time error at line no. 8 as null value cannot be casted.
Correct Answer : 2
Your Answer :
QuestionID : 9796 Subject Name Core Java
Q49. Which of the following are true about the class defined inside an
interface
1. a. it is not possible in the java Language.
2. b. The class is always public.
3. c. The class is always static.
4. d. The class method cannot call the method declared in the interface.
Correct Answer : 3
Your Answer :
QuestionID : 9820 Subject Name Core Java
Q50. Which of the Listener classes have corresponding adpter classes.
[Link]
[Link]
[Link]
[Link]
1. 1,2
2. 2,4
3. 3,4
4. 1,4
Correct Answer : 4
Your Answer :
QuestionID : 9835 Subject Name Core Java
Q51. Which of the following is correct?
1. 128 >> 1 gives 64
2. 128 >>> 1 gives 64
3. 128 >>> 1 gives –64
4. both (a) and (b)
Correct Answer : 4
Your Answer :
QuestionID : 9836 Subject Name Core Java
Q52. Which of the following wrapper classes have a booleanValue() method?
1. All wrapper classes
2. All wrapper classes except void
3. All wrapper classes that also implement the compareTo() method
4. only the class Boolean
Correct Answer : 4
Your Answer :
QuestionID : 9856 Subject Name Core Java
Q53. Which of the following is a legal return type of a method,overloading
the following method:
public void add(int a) {…}
1. int
2. void
3. Can be anything
4. none of the above
Correct Answer : 3
Your Answer :
QuestionID : 9860 Subject Name Core Java
Q54. Java supports multidimensional arrays.
Correct Answer : T
Your Answer :
QuestionID : 9874 Subject Name Core Java
Q55. The following code will give
1: class Test
2: {
3: static void show()
4: {
5: [Link]("Static method in Test");
6: }
7: }
8: public class Q4 extends Test
9: {
10: void show()
11: {
12: [Link]("Overridden static method in Q4");
13: }
14: public static void main(String[] args)
15: {
16: }
17: }
1. Compilation error at line 3.
2. Compilation error at line 10.
3. No compilation error, but runtime exception at line 3.
4. No compilation error, but runtime exception at line 10.
Correct Answer : 2
Your Answer :
QuestionID : 9881 Subject Name Core Java
Q56. What will be the output ?
class abc
{
public static void main(String[] args)
{
StringBuffer sb1=new StringBuffer("abcd");
StringBuffer sb2=sb1;
if ([Link](sb2))
{
[Link]("OK");
}
else
[Link]("NOT OK");
}
}
1. Compile-Error.
2. OK
3. NOT OK
4. Runtime-Error
Correct Answer : 2
Your Answer :
QuestionID : 9892 Subject Name Core Java
Q57. The code outside of the class Outer can instantiate class Inner.
Correct Answer : F
Your Answer :
QuestionID : 9896 Subject Name Core Java
Q58. Comparison/Logical operators are used for testing and magnitude.
Correct Answer : T
Your Answer :
QuestionID : 9906 Subject Name Core Java
Q59. The following code will print
class Demo
{
public static void main(String[] args)
{
[Link]("2"+3+4);
[Link](2+3+"4");
}
}
1. 234 & 54
2. 27 & 234
3. none of the above
4. 234 & 234
Correct Answer : 1
Your Answer :
QuestionID : 9942 Subject Name Core Java
Q65. What will be the result of invoking the wait()method on object without
ensuring that the current thread holds the lock of the object?
1. The code will compile to fail
2. Nothing special will happen
3. An IllegalMonitorStateException will be thrown if the wait() method is
called while the current thread does not hold the lock of the object.
4. The thread will be blocked until it gains the lock of the object
Correct Answer : 3
Your Answer :
QuestionID : 9944 Subject Name Core Java
Q66. All the values of the expressions on the right-hand side of the
assignments are implicitly promoted to type int.
Correct Answer : T
Your Answer :
QuestionID : 9960 Subject Name Core Java
Q67. Which of the following are true?
1. Component extends Container
2. MenuItem extends Component
3. Container extends Component
4. MenuComponent extends Component
Correct Answer : 3
Your Answer :
QuestionID : 9968 Subject Name Core Java
Q68. Which methods can be called on objects implementing the Map
interface?
(a)contains(Object o)
(b)addAll(Collection c)
(c)remove(Object o)
(d)values()
(e)toArray()
1. a,b and e
2. b and c
3. c and d
4. b,c,d and e
Correct Answer : 3
Your Answer :
QuestionID : 9970 Subject Name Core Java
Q69. Using [Link](1); in try block will not allow finally code to execute.
Correct Answer : T
Your Answer :
QuestionID : 9997 Subject Name Core Java
Q70. class Demo
{
static int total = 10;
public void divide(int a, int b) {
try {
int c = a / b;
} catch (Exception e) {
[Link]("Exception ");
} finally {
[Link]("Finally");
}
}
}
}
public static void main (String args[])
{
TestClass nt1=new TestClass();
TestClass nt2=new TestClass();
TestClass nt3=new TestClass();
[Link]();
[Link]();
[Link]();
}
}
1. The code does not compile
2. the code compiles
and runs 3 non ending non demon threads.
3. the code compiles
and runs only 1 non ending non demon thread.
4. non of the above
Correct Answer : 3
Your Answer :
QuestionID : 10016 Subject Name Core Java
Q72. Which are the valid ways to create DataInputStream streams?
1. new DataInputStream();
2. new DataInputStream("[Link]");
3. new DataInputStream(new File("[Link]"));
4. new DataInputStream(new FileInputStream("[Link]"));
Correct Answer : 4
Your Answer :
QuestionID : 10019 Subject Name Core Java
Q73. public class Test {
[Link]("Non-static print");
}
public static void print()
{
[Link]("Static print");
}
[Link]();
}
1. Non-static print
2. Static print
3. Compilation error
4. Runtime Error
Correct Answer : 3
Your Answer :
QuestionID : 10034 Subject Name Core Java
Q74. Operand stack in java is a 32 bit wide
Correct Answer : T
Your Answer :
QuestionID : 10047 Subject Name Core Java
Q75. Does the following piece of code compile ? if yes , what is output ?
class Test09
{
static int tomb ( char a )
{
throw new NumberFormatException();
}
public static void main(String args[])
{
try
{
tomb(`a`);
}
catch ( Exception e )
{
[Link] ( " Done " ) ;
}
}
}
new Test();
public Test () {
[Link]("In test");
[Link](this);
if (temp > 5) {
[Link](temp);
}
1. 0 - 65, 535
2. (–128) – 127
3. (–32,768) – 32,767
4. (–256) – 255
Correct Answer : 2
Your Answer :
QuestionID : 10455 Subject Name Core Java
Q91. what information is needed to create a TCP socket?
1. the local system s IP Address
2. the local systems port number
3. the remote system s IP Address
4. the remote system s port number
Correct Answer : 3
Your Answer :
QuestionID : 10471 Subject Name Core Java
Q92. Finalise wont be called more than once on the same object
Correct Answer : T
Your Answer :
QuestionID : 10473 Subject Name Core Java
Q93. ClassLoader is a public class and extends object class
Correct Answer : T
Your Answer :
QuestionID : 10495 Subject Name Core Java
Q94. getCause() are methods of which class.
1. Throwable
2. IOException
3. RunTimeException
4. none of the above
Correct Answer : 1
Your Answer :
QuestionID : 10498 Subject Name Core Java
Q95. inner classes are visible to other classes in the same package.
Correct Answer : F
Your Answer :
QuestionID : 10966 Subject Name Core Java
Q96. A constructor must initialize all the fields of a class.
Correct Answer : F
Your Answer :
QuestionID : 11001 Subject Name Core Java
Q97. ClassLoader is a public class and extends object class
Correct Answer : T
Your Answer :
QuestionID : 11003 Subject Name Core Java
Q98. Externalizable is marker Interface
Correct Answer : F
Your Answer :
QuestionID : 11009 Subject Name Core Java
Q99. abstract classes can contain native methods
Correct Answer : T
Your Answer :
QuestionID : 11036 Subject Name Core Java
Q100. What is the output of the following program?
class test
{
int i=(int)34.3E38
[Link](i);
}
1. It is equal to maximum value of the integer;
2. It gives Runtime [Link] is greator than limits of Integer .
3. It gives Compile time [Link] is greator than limits of Integer.
4. 343000000
Correct Answer : 1
Your Answer :