0% found this document useful (0 votes)
3 views

CoreJava1

The document contains a series of questions and answers related to Core Java, including topics such as packages, method declarations, exception handling, and class structures. Each question includes a correct answer and the user's answer, highlighting areas of misunderstanding. The document serves as a quiz or assessment tool for evaluating knowledge in Java programming.

Uploaded by

adef17354
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CoreJava1

The document contains a series of questions and answers related to Core Java, including topics such as packages, method declarations, exception handling, and class structures. Each question includes a correct answer and the user's answer, highlighting areas of misunderstanding. The document serves as a quiz or assessment tool for evaluating knowledge in Java programming.

Uploaded by

adef17354
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

dDw tMjIw Njg5MjE

QuestionID : 1207 Subject Name Core Java


Q1. A package is a collection of
1. Classes
2. interfaces
3. editing tools
4. classes and interfaces
Correct Answer : 4
Your Answer : 1
QuestionID : 1233 Subject Name Core Java
Q2. Which of the following assignments are valid?
1. float x = 123.4;
2. Long m = 023;
3. Int n = (int) false;
4. int y = 0x756;
Correct Answer : 4
Your Answer : 1
QuestionID : 1278 Subject Name Core Java
Q3. A method declared as static cannot access non-static class members.
Correct Answer : T
Your Answer : T
QuestionID : 1303 Subject Name Core Java
Q4. Java always provides a default constructor to a class.
Correct Answer : T
Your Answer : T
QuestionID : 1313 Subject Name Core Java
Q5. Any method in super class can be overridden in its subclass.
Correct Answer : F
Your Answer : F
QuestionID : 1326 Subject Name Core Java
Q6. A catch can have comma-separated multiple arguments.
Correct Answer : F
Your Answer : F
QuestionID : 1345 Subject Name Core Java
Q7. When we invoke repaint( ) for a Component, the AWT invokes the
method :
1. draw()
2. show()
3. update()
4. paint()
Correct Answer : 3
Your Answer : 1
QuestionID : 1390 Subject Name Core Java
Q8. Declaring a method synchronized guarantees that the deadlock cannot
occur.
Correct Answer : T
Your Answer : T
QuestionID : 9331 Subject Name Core Java
Q9. Which of the following are valid methods?
1. public static void aMethod() {}
2. void static aMethod() {}
3. public private void aMethod() {}
4. private aMethod() {}
Correct Answer : 1
Your Answer : 1
QuestionID : 9336 Subject Name Core Java
Q10. Which of the following are true?
1. A component may handle its own events by adding itself as an event
listener.
2. A component may handle its own events by overridding its event-
dispatching method.
3. A component may not handle oits own events.
4. A component may handle its own events only if it implements the the
handleEvent() method.
Correct Answer : 1
Your Answer : 1
QuestionID : 9342 Subject Name Core Java
Q11. A static member class can contain non-static fields.
Correct Answer : T
Your Answer : F
QuestionID : 9349 Subject Name Core Java
Q12. What will be the result of executing the following code?

public static void main(String argsQ)


{
char digit=`a`;
for(inti=0;i<10;i++)
{
switch(digit)
{
case`x`:
{
int j=0;
system.out.println(j);
}
default:
{
int j=100;
System.out.println(j);
}
}
}
int i=j;
System.out.println(j);
}
1. 100 will be printed 10 times and then there will be a runtime exception.
2. The code will not compile because the variable i cannot be declared
twice within the main() method.
3. The code will not be compile because the variable j cannot be declared
twice within the switch statement.
4. None of these.
Correct Answer : 4
Your Answer : 0
QuestionID : 9364 Subject Name Core Java
Q13. What is the results of the following operation?
System.out.println(4|3);
1. 6
2. 0
3. 1
4. 7
Correct Answer : 4
Your Answer :
QuestionID : 9369 Subject Name Core Java
Q14. Which of the following methods helps in getting the local host ip?
1. getLocalHost()
2. getRemoteHost()
3. getIpAddress()
4. getHost()
Correct Answer : 1
Your Answer :
QuestionID : 9379 Subject Name Core Java
Q15. In OSI N/W architecture, the dialogue control & token management are
responsibilities of.......
1. Network
2. Application
3. Session
4. Data Link
Correct Answer : 3
Your Answer :
QuestionID : 9394 Subject Name Core Java
Q16. what will be the result of compiling and running the following
code with assertions enabled?
public class TernaryAssertion {
public static void assertBounds(int low,int high,int value){
assert(value>low?value< high:false):(value< high?\"too low\"
:\"too high");
}
public static void main(string[] args) {
assertBounds(100,200,150);
}
}
1. the compilation fails because the method name assertBounds cannot
begin with the keyword assert.
2. the compilation fails because the assert statement is invalid.
3. the compilation succeeds and the program runs without errors.
4. none
Correct Answer : 3
Your Answer :
QuestionID : 9419 Subject Name Core Java
Q17. //Filename:MyClass.java
public class MyClass
{
public static void main(String[] args)
{
A[] arrA;
B[] arrB;

arrA=new A[10];
arrB=new B[20];
arrA=arrB; //(1)
arrB=(B[])arrA; //(2)
arrA=new A[10];
arrB=(B[])arrA; //(3)
}
}
class A{}
class B extends A{}
Given the following program,which statement is true.
Select the correct answer.
1. The program will fail to compile because of the assignment at (1)
2. The program will throw a java.lang.ClassCast Exception in the
assignment at (2) when

run.
3. The program will throw a java.lang.ClassCast Exception in the
assignment at (3) when
run.
4. The program will compile and run without errors,even if the (B[]) cast
in the statements at (2) and (3) is removed.
Correct Answer : 3
Your Answer :
QuestionID : 9474 Subject Name Core Java
Q18. What is java virtual machine?
1. A hardware manifactured by SUN Microsystem,Inc.
2. A software
3. A device like chip embedded in computer harddisk
4. An Aplication
Correct Answer : 2
Your Answer :
QuestionID : 9481 Subject Name Core Java
Q19. 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 : 9483 Subject Name Core Java
Q20. class Question72
{
public Question72()throws IOException
{
throw new IOExeception();
}
}

public abstract class Question73 extends Question72


{
public abstract void method();
}
1. will cause a compiler error-non-abstract classes cannot be extended to
abstract classes.
2. will cause a compiler error-a constructor must be provided which may
or may not throw an Exception
3. will cause a compiler error-a constructor must be provided which must
throw an IOException or one of its super types.
4. will not cause any compiler error-the class definition is perfectly legal
Correct Answer : 3
Your Answer :
QuestionID : 9492 Subject Name Core Java
Q21. Which one of this is not a legal member declaration with in a class?
1. 1. static int a;
2. 2. final Object [] fudge = { null };
3. 3. abstract int t;
4. 4. native void sneeze();
Correct Answer : 3
Your Answer :
QuestionID : 9525 Subject Name Core Java
Q22. if("String".replace(`T`,`t`) =="String")
System.out.println("Equal");
else
System.out.println(" not Equal");
1. the code will compile and print Equal
2. the code will compile and print not Equal
3. the code will cause compile error
4. ..
Correct Answer : 1
Your Answer :
QuestionID : 9557 Subject Name Core Java
Q23. if( "STRING".toUpperCase() == "STRING")
System.out.println("Equal");
else
System.out.println("Not Equal");
1. the code will compile and print "Equal".
2. the code will compile and print "Not Equal".
3. the code will cause compile error.
4. None.
Correct Answer : 1
Your Answer :
QuestionID : 9590 Subject Name Core Java
Q24. Which statement is true? Select the one correct answer.
1. The compiler will fail to compile code that explicitly tries to call the
finalize() method.
2. An overriding finalize() method in any class can always throws
checked exceptions.
3. The finalize method() can be overloading.
4. The body of the finalize() method can only access other objects that are
eligible for gabage collection.
Correct Answer : 3
Your Answer :
QuestionID : 9640 Subject Name Core Java
Q25. Interface method can be declared with the following modifiers
a.public
b.none (i.e. no access modifiers)
c.private.
d. static
e. Native
f.Synchronized
1. abc
2. abd
3. aef
4. acf
Correct Answer : 2
Your Answer :
QuestionID : 9654 Subject Name Core Java
Q26. You can explicitly drop a object reference by setting the value
of a variable whose data type is a reference type to
1. null
2. NAN
3. 0
4. none of these
Correct Answer : 1
Your Answer :
QuestionID : 9679 Subject Name Core Java
Q27. void infiniteloop()
{
byte b=1;
while(++b>0)
;
System.out.println("welcome to java");
}
1. loop never ends(infinite loop)
2. prints nothing
3. Prints "Welcome to java"
4. compilation error at line 5. ++operator should not be used for byte type
variables.
Correct Answer : 3
Your Answer :
QuestionID : 9688 Subject Name Core Java
Q28. The following code will give:
1:class Test
2:{
3: void show()
4: {
5: System.out.println("non-static method in Test");
6: }
7:
8:}
9:public class Q3 extends Test
10:{
11: static void show()
12: {
13: System.out.println("Overriden non-static method in Q3");
14: }
15: public static void main(String [] args)
16: {
17: Q3 a=new Q3();
18: }
19:}
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 : 9704 Subject Name Core Java
Q29. String str="Welcome";
str.concat("to java!");
System.out.println(str);

1. Strings are immutable, compilation error at line 3.


2. Strings are immutable, runtime exception at line 3.
3. prints "Welcome"
4. prints "Welcome to Java!"
Correct Answer : 3
Your Answer :
QuestionID : 9779 Subject Name Core Java
Q30. Which of the following are identifier names in java?
1. %abcd
2. package
3. 5abcd
4. _a_long_name
Correct Answer : 4
Your Answer :
QuestionID : 9794 Subject Name Core Java
Q31. #Q56 Read the following code ,which is a part of a Synchronized
method of a monitor

public Synchronized void someMethod()


{
// do some code here
try
{
Thread.sleep(500);
}
catch(InterruptExeption e )
{

// do some crap here


}
// more & more code here

1. a. The code causes compilation error –sleep cannot be called inside


synchronized method
2. b. The code causes compilation error - sleep is not a static method of
java.lang.Thread
3. c. The thread sleep for atleast 500 millisec in this method if not
interrupted.
4. d.When the thread “goes to sleep” it releases the lock on the Object.
Correct Answer : 3
Your Answer :
QuestionID : 9853 Subject Name Core Java
Q32. Dynamic method dispatch is the mechanism by which a call to an
overridden function is resolved at run time,rather than at compile
time.
Correct Answer : T
Your Answer :
QuestionID : 9860 Subject Name Core Java
Q33. Java supports multidimensional arrays.
Correct Answer : T
Your Answer :
QuestionID : 9877 Subject Name Core Java
Q34. Which of the following declare an array of string objects?

(a) String[ ] s;
(b) String [ ]s;
(c) String[ s];
(d) String s[ ];
1. a, b,c,d
2. a,b,d
3. b,c,d
4. a,c,d
Correct Answer : 2
Your Answer :
QuestionID : 9887 Subject Name Core Java
Q35. Which labeled line will generate error.
public class test
{
public static void main(String[] args)
{
char c;
int i;
c=`A`; //1
i=c; //2
c=i+1; //3
c++; //4

}
}
1. The line labeled 1
2. The line labeled 2
3. The line labeled 3
4. The line labeled 4
Correct Answer : 3
Your Answer :
QuestionID : 9932 Subject Name Core Java
Q36. Which of the following are true about the Error and Exception
classes?
1. Both classes extends Throwable
2. The error class is final and the exception class is not.
3. The exception class is final and the error class is not.
4. Both class implement Throwable.
Correct Answer : 1
Your Answer :
QuestionID : 9987 Subject Name Core Java
Q37. What class must an inner class extends.
1. The Top level class
2. Any class or interface
3. The object class
4. It must extend an interface
Correct Answer : 2
Your Answer :
QuestionID : 10034 Subject Name Core Java
Q38. Operand stack in java is a 32 bit wide
Correct Answer : T
Your Answer :
QuestionID : 10043 Subject Name Core Java
Q39. import java.io.*;
public class TestClass
{
public static void main(String args[]) throws IOException
{
PrintStream pr=new PrintStream(new FileOutputStream("outfile"));
System.out=pr;
System.out.println("Lets see what I see now??????");
}
}
1. compile time error
2. cannot assign a value to final variable out
3. the code compiles and run successfully .A file called "outfile" is
created and "lets see what i see now??" is printed in the same.
4. it will do nothing
Correct Answer : 2
Your Answer :
QuestionID : 10098 Subject Name Core Java
Q40. Given that a Button can generate an ActionEvent which listener would
you expect to have to implement, in a class which would handle this event?
1.
FocusListener
2. ComponentListener
3. WindowListener
4. ActionListener
Correct Answer : 4
Your Answer :
QuestionID : 10101 Subject Name Core Java
Q41. Exception is sub-class of error
Correct Answer : F
Your Answer :
QuestionID : 10162 Subject Name Core Java
Q42. What is the result of compiling and running the following code:

public class Test {

static int total = 10;

public static void main (String args []) {

new Test();

public Test () {

System.out.println("In test");

System.out.println(this);

int temp = this.total;

if (temp > 5) {

System.out.println(temp);

1. The class will not compile


2. The compiler reports and error at line 2
3. The compiler reports an error at line 9
4. The value 10 is one of the elements printed to the standard output
Correct Answer : 4
Your Answer :
QuestionID : 10224 Subject Name Core Java
Q43. In the following code A and D will compile without error.
A.StringBuffer sbl= "abcd";
B.Boolean b=new Boolean("abcd");
C:byte b=255;
D:int x=0x1234;
E:float fi=1.2;
Correct Answer : F
Your Answer :
QuestionID : 10240 Subject Name Core Java
Q44. String str="hello";
String str1=str+"world";
String str2="helloworld";
if(str1==str2)
System.out.println("equal");
else
System.out.println("not equal");

1. compiler error
2. equal
3. not equal
4. exception
Correct Answer : 3
Your Answer :
QuestionID : 10245 Subject Name Core Java
Q45. which of these methods from the collection interface will return the
value
true if the collection was modified during the operation
a.contains()
b.add()
c.containsAll()

d.retainAll()
e.clear()
1. b,d
2. c,d
3. d,a
4. d,e
Correct Answer : 1
Your Answer :
QuestionID : 10266 Subject Name Core Java
Q46. Which of the following are Java keywords (as opposed to reserved
words)?

1. goto
2. malloc
3. extends
4. FALSE
Correct Answer : 3
Your Answer :
QuestionID : 10440 Subject Name Core Java
Q47. memeber variables be synchronized
Correct Answer : T
Your Answer :
QuestionID : 10442 Subject Name Core Java
Q48. Abstract clases may contain final methods.
Correct Answer : T
Your Answer :
QuestionID : 10446 Subject Name Core Java
Q49. Garbage collection is a process that does,
1. reclaiming memory occupied by objects that are no longer needed and
making it available for new objects.
2. reclaiming memory occupied by objects that are no longer needed.
3. None
4. None
Correct Answer : 1
Your Answer :
QuestionID : 10517 Subject Name Core Java
Q50. When outer class is inherited then inner class is automaticaly inherited.
Correct Answer : F
Your Answer :

You might also like