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

CoreJava2

The document consists of a series of questions and answers related to Core Java, including topics such as expressions, class accessibility, method implementation, and object-oriented principles. Each question includes a correct answer and the user's answer, highlighting discrepancies in understanding. The document serves as a quiz or assessment tool for evaluating knowledge in Core 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)
2 views

CoreJava2

The document consists of a series of questions and answers related to Core Java, including topics such as expressions, class accessibility, method implementation, and object-oriented principles. Each question includes a correct answer and the user's answer, highlighting discrepancies in understanding. The document serves as a quiz or assessment tool for evaluating knowledge in Core 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/ 15

dDw tMjIw Njg5MjE

QuestionID : 1184 Subject Name Core Java


Q1. What is the result of the expression (1 & 2) + (3 | 4) in base ten
1. 1
2. 2
3. 8
4. 7
Correct Answer : 4
Your Answer : 4
QuestionID : 1216 Subject Name Core Java
Q2. Which keyword can protect a class in a package from accessibility by the
classes outside the package?
1. private
2. protected
3. Final
4. Don`t use any keyword at all (make it default)
Correct Answer : 4
Your Answer : 1
QuestionID : 1237 Subject Name Core Java
Q3. Consider the following statements :
int x = 10, y = 15;
x = (x < y) ? (y + x) : (y - x);
What will be the value of x after executing these statements?
1. 10
2. 25
3. 15
4. 5
Correct Answer : 2
Your Answer : 2
QuestionID : 1266 Subject Name Core Java
Q4. The import statement is always the first noncomment statement in a Java
program file.
Correct Answer : F
Your Answer : T
QuestionID : 1267 Subject Name Core Java
Q5. Objects are passed to a method by use of call-by-reference.
Correct Answer : T
Your Answer : T
QuestionID : 1283 Subject Name Core Java
Q6. Every method of a final class is implicitly final.
Correct Answer : T
Your Answer : T
QuestionID : 1318 Subject Name Core Java
Q7. A static class method can be invoked by simply using the name of the
method alone.
Correct Answer : T
Your Answer : T
QuestionID : 1347 Subject Name Core Java
Q8. Which of the following methods can be used to change the size of a
component?
1. dimension( )
2. size()
3. setSize( )
4. resize( )
Correct Answer : 3
Your Answer : 4
QuestionID : 1366 Subject Name Core Java
Q9. With a Border layout manager, the component at the centre gets all the
space that is left over, after the components at North and South have been
considered.
Correct Answer : T
Your Answer : T
QuestionID : 1367 Subject Name Core Java
Q10. The default layoutmanager of the content pane of a JFrame is the
flowlayout manager.
Correct Answer : F
Your Answer : T
QuestionID : 1383 Subject Name Core Java
Q11. When we implement the Runnable interface, we must define the method
:
1. init()
2. run()
3. runnable()
4. resume()
Correct Answer : 2
Your Answer : 3
QuestionID : 9318 Subject Name Core Java
Q12. A ______ is an object that originates or "fire" events.
1. Event
2. Source
3. Trigger
4. None of above.
Correct Answer : 2
Your Answer : 3
QuestionID : 9327 Subject Name Core Java
Q13. public class Prog1
{
public static void main(String args[])
{
int k=1;
int i=++k+k++ + +k;
System.out.println(i);
}
}
1. compilation error
2. value 3 is printed
3. value 4 is printed
4. value 7 is printed
Correct Answer : 4
Your Answer : 1
QuestionID : 9329 Subject Name Core Java
Q14. A finally block is executed only when an exception is thrown,
even if no catch matches it.
Correct Answer : F
Your Answer : T
QuestionID : 9341 Subject Name Core Java
Q15. public class DefaultvalueTest
{
int [] ia=new int[1];
boolean b;
int i;
Object o;
public static void main(String[] args)
{
DafultvalueTest instance=new DefaultvalueTest();
instance.print();
}

public void print()


{
System.out.println(ia[]+ " "+b+" "+i+" "+o);
}
}
1. The program will fail to compile because of uninitialized variables.
2. The program will
throw a java.lang.NullPionterException when run.
3. The program will print "0 flase NaN null"
4. The program will print "0 flase 0 null".
Correct Answer : 4
Your Answer : 3
QuestionID : 9391 Subject Name Core Java
Q16. What will happen when you attempt to compile and run the following
code?
class Background implements Runnable
{
int i=0;
public int run()
{
while (true)
{
i++;
System.out.println("i="+i);
}//End while
reurn 0;
}//End run
}
1. It will compile and the run method will print out the increasing value of
i
2. It will compile and calling start will print out the increasing value of i
3. The code will cause an error at the compile time
4. Compilation will cause an error because while cannot take parameter of
true
Correct Answer : 3
Your Answer : 1
QuestionID : 9395 Subject Name Core Java
Q17. Which statements is true about the following code?
//Filename:Myclass.java
abstract class Myclass implements interface1,interface2
{
public void f(){}
public void g() {}
}
interface interface1
{
int val_A=1;
int val_B=2;
void f();
void g();
}
interface interface2
{
int val_B=3;
int val_c=4;
void g();
void h();
}
1. Interface1 and Interface2 do not match,therefore,Myclass cannot
implement them both.
2. Myclass only implements interface1.Implementation for void h() from
interface2 is missing.
3. The declarations of void g() in the two interfaces conflict,therefore,the
code will not complete
4. Nothing is wrong with the code ,it will cpmpile without errors.
Correct Answer : 4
Your Answer : 0
QuestionID : 9431 Subject Name Core Java
Q18. Is this Tre or False . In Java a final class must be sub-classed before it
can be used.
Correct Answer : F
Your Answer : T
QuestionID : 9451 Subject Name Core Java
Q19. Attribute of an Object is also known as its ________.
1. state
2. method
3. behavior
4. procedures
Correct Answer : 1
Your Answer : 3
QuestionID : 9466 Subject Name Core Java
Q20. import java.awt.*;

public class test extends Frame


{
Button bnorth=new Button("NORTH");
Button bsouth=new Button("South");
Button beast=new Button("East");
Button bwest=new Button("West");
Button bcenter=new Button("Center");

public test()
{
setLayout(new FlowLayout());

add(bsouth);
add(bwest);
add(beast);
add(bnorth);

add(bcenter);
setLayout(new BorderLayout());
validate();
setSize(300,300);
setVisible(true);
}

public static void main(String args[])


{
test t=new test();

}
}

1. will compile and run but no component is visible


2. will causes a compilation error - a layout cannot be set after component
has
been added with preset layout manager
3. will causes a runtime error - a layout cannot be set after component has

been added with preset layout manager


4. will compile and throws no runtime exception.Only the button with
"center
" is visible and occupies whole screen
Correct Answer : 1
Your Answer : 1
QuestionID : 9481 Subject Name Core Java
Q21. Which method is used to determine the class of an object?
1. getClass()
2. getObject()
3. instanceOf()
4. forName()
Correct Answer : 1
Your Answer : 3
QuestionID : 9502 Subject Name Core Java
Q22. what command in the java 2SDK should be used to execute the main()
method of class named smallprog ?
1. java Smallprog
2. javac Smallprog
3. java Smallprog.java
4. javac Smallprog.java
Correct Answer : 1
Your Answer : 0
QuestionID : 9506 Subject Name Core Java
Q23. The code below draws a line. What color is the line?
g.setColor(Color.red.green.yellow.red.cyan);
g.drawLine(0,0,100,100);
1. Red
2. Green
3. Black
4. LightGray
Correct Answer : 3
Your Answer : 1
QuestionID : 9541 Subject Name Core Java
Q24. Name the collection interface implemented by the vector class
1. Set
2. Map
3. List
4. Vector
Correct Answer : 3
Your Answer : 4
QuestionID : 9581 Subject Name Core Java
Q25. Which of the following statements are true?

Select all valid answers.

a) The result of the expression (1 + 2 + "3") would be the string "33".


b) The result of the expression ("1" + 2 + 3) would be the string "15".
c) The result of the expression (4 + 1.0f) would be the float value 5.0.
d) The result of the expression (10 / 9) would be the int value 1.
e) The result of the expression (`a` + 1) would be the char value `b`.
1. (a),(b),(e)
2. (a),(c),(d)
3. (b),(c),(d)
4. (c),(d),(e)
Correct Answer : 2
Your Answer : 1
QuestionID : 9650 Subject Name Core Java
Q26. Which of the following are valid runtime options?
1. -enableassertions
2. -source 1.4
3. -disablesystemassertions
4. (1) and (3)
Correct Answer : 4
Your Answer : 4
QuestionID : 9673 Subject Name Core Java
Q27. Java compiler stores the .class files in the path specified in
CLASSPATH environmental variable
Correct Answer : F
Your Answer : T
QuestionID : 9698 Subject Name Core Java
Q28. public interface AQuestion
{
public abstract void someMethod() throws Exception;
}
a class implementing this interface should be
1. necessarily be an abstract class
2. should have the method public abstract void someMethod()
3. should have the method public void someMethod which has to throw
an exception which is a subclass of java.lang.Exception
4. should have the method public void someMethod()which need not
throw an Exception.
Correct Answer : 3
Your Answer : 1
QuestionID : 9778 Subject Name Core Java
Q29. Assume that th is an instance holding a thread object. th.start() causes
the
the thread to start running and eventually complete its execution.The object
reference by th is not accessible any more and is garbage collected
when the garbage collector runs
Correct Answer : F
Your Answer : T
QuestionID : 9797 Subject Name Core Java
Q30. You are taking over an aquarium simulation project.Your predecessor
had created a generic Fish class

that includes an oxygenConsumption method declared as follows:


public float oxygenConsumption(float temperature)
The aquarium simulation sums oxygen consumption for all fish in tank with
the folowing code

fragement,where fishes in an array of Fish object references:


float total=0;
for(int i=0;i < fishes.lenght;i++)
{
total+=fishes[i].oxygenConsumption(t);
}
You are writing a subclass for a particular fish species.Your task is to provide
a method with

species-specific metabolism data that will transparently fit into the


simulation.Do you want to overload

or override the oxygenConsumption method?


1. overload
2. override
3. Nothing is required
4. Either overload or override
Correct Answer : 2
Your Answer : 2
QuestionID : 9836 Subject Name Core Java
Q31. 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 : 4
QuestionID : 9874 Subject Name Core Java
Q32. The following code will give

1: class Test
2: {
3: static void show()
4: {
5: System.out.println("Static method in Test");
6: }
7: }
8: public class Q4 extends Test
9: {
10: void show()
11: {
12: System.out.println("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 : 1
QuestionID : 9906 Subject Name Core Java
Q33. The following code will print

1: if( new Boolean("true") == new Boolean("true"))


2: System.out.println("True");
3: else
4: System.out.println("False");
1. Compilation error.
2. No compilation error, but runtime exception.
3. Prints "True".
4. Prints "False".
Correct Answer : 4
Your Answer : 3
QuestionID : 9913 Subject Name Core Java
Q34. which statements are true about locks?

1.A thread can hold more than one lock at a time.


2.Invoking wait() on a Thread object will relinquish all locks held by the
thread.
3.invoking wait() on an object whose lock is held by the current thread will
relinquish the lock.
4.Invoking notify() on a object whose lock is held by the current thread will
relinquish the lock.
5. Multiple threads can hold the same lock at the same time.
6.The thread will be blocked until it gains the lock of the object.
1. 1,3,6
2. 3,6,4
3. 1,3
4. 1,2,5,6
Correct Answer : 3
Your Answer : 4
QuestionID : 9935 Subject Name Core Java
Q35. Which expression will evaluate to true?
1. "HELLO THERE".equals("hello there")
2. ("hello".concat("there")).equals("hello there")
3. "Hello There".compareTo("hello there")==0
4. "Hello there".toLowerCase().equals("hello there")
Correct Answer : 4
Your Answer : 4
QuestionID : 9946 Subject Name Core Java
Q36. Which method is not defined in the string class.
1. hashCode()
2. length()
3. concat(String)
4. reverse()
Correct Answer : 4
Your Answer : 1
QuestionID : 9983 Subject Name Core Java
Q37. _______ is an expression of pure syntax.
1. Interface.
2. Virtual function.
3. pure virtual function.
4. none of the above.
Correct Answer : 1
Your Answer : 1
QuestionID : 9986 Subject Name Core Java
Q38. Which of the following are true?
1. Window extends Frame
2. Applet extends Container
3. Panel extends Container
4. Scrollpane extends Panel
Correct Answer : 3
Your Answer : 2
QuestionID : 10092 Subject Name Core Java
Q39. How are remote object parameters transferred between client and
server?
1. A proprietary protocol that is determined by the vendor of the RMI
implementation
2. Standard Java Serialization
3. Internet Inter-ORB protocol(IIOP)
4. Java Remote Method Protocol(JRMP)
Correct Answer : 2
Your Answer : 3
QuestionID : 10120 Subject Name Core Java
Q40. Consider the following example:

class First {

public First (String s) {

System.out.println(s);

public class Second extends First {

public static void main(String args []) {

new Second();

What is the result of compiling and running the Second class?

1. Nothing happens
2. A string is printed to the standard out
3. An instance of the class First is generated
4. The class second will not compile as there is no null parameter
constructor in the class First
Correct Answer : 4
Your Answer : 2
QuestionID : 10162 Subject Name Core Java
Q41. 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 : 3
QuestionID : 10172 Subject Name Core Java
Q42. Which dynamic class is threadsafe.
1. vector
2. ArrayList
3. Linkedlist
4. None of these
Correct Answer : 1
Your Answer : 3
QuestionID : 10188 Subject Name Core Java
Q43. a documentation comment in java is given as
1. /***...*/
2. /**...**/
3. /*...**/
4. /**...*/
Correct Answer : 4
Your Answer : 2
QuestionID : 10193 Subject Name Core Java
Q44. Which of the following is not a keyword?
1. main
2. public
3. static
4. void
Correct Answer : 1
Your Answer : 1
QuestionID : 10215 Subject Name Core Java
Q45. What will be output of following

System.out.println(4.0/0.0);
1. -Infinity
2. Infinity
3. Compile time error
4. Will throw exception
Correct Answer : 2
Your Answer : 4
QuestionID : 10248 Subject Name Core Java
Q46. class A
{
public static void main(String[] args)
{
String str="ram-shyam";
System.out.println(str.substring(4,10));
}
}

what will be output


1. shyam
2. Ram
3. Compile time error
4. Runtime error
Correct Answer : 4
Your Answer : 1
QuestionID : 10254 Subject Name Core Java
Q47. what are the valid statments
1)ch\u0061r vij;
2)\u0063h\u0061r vij1 ;
3)Char vij2;
4)none
1. 1)is correct
2. 2)is correct
3. Both 1) and 2) are correct
4. All are incorrect
Correct Answer : 3
Your Answer : 0
QuestionID : 10440 Subject Name Core Java
Q48. memeber variables be synchronized
Correct Answer : T
Your Answer : T
QuestionID : 10484 Subject Name Core Java
Q49. bind and rebind are methods of remote interface
Correct Answer : F
Your Answer : T
QuestionID : 10990 Subject Name Core Java
Q50. Inner class in java can be Static?
Correct Answer : T
Your Answer : T

You might also like