0% found this document useful (0 votes)
205 views11 pages

Core Java Quiz Questions and Answers

The document contains a series of questions and answers related to Core Java, covering various topics such as variable assignments, class methods, exceptions, and data structures. Each question includes a correct answer and the user's answer, with some questions addressing Java concepts like abstract classes, interfaces, and error handling. The document serves as a quiz or test format for evaluating knowledge in Core Java programming.

Uploaded by

adef17354
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
205 views11 pages

Core Java Quiz Questions and Answers

The document contains a series of questions and answers related to Core Java, covering various topics such as variable assignments, class methods, exceptions, and data structures. Each question includes a correct answer and the user's answer, with some questions addressing Java concepts like abstract classes, interfaces, and error handling. The document serves as a quiz or test format for evaluating knowledge in Core Java programming.

Uploaded by

adef17354
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

dDw tMjIw Njg5MjE

QuestionID : 1192 Subject Name Core Java


Q1. 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 : 1197 Subject Name Core Java
Q2. Which of the following lines will not compile?
1. byte b1 = 5, b2 = 3, b3;
2. short s = 25;
3. b2 = s;
4. b3 = b1 * b2;
1. Line 1 and Line 3
2. Line 4 only
3. Line 3 and Line 4
4. Line 1 only
Correct Answer : 3
Your Answer : 3
QuestionID : 1307 Subject Name Core Java
Q3. It is perfectly legal to refer to any instance variable inside of a static
method
Correct Answer : F
Your Answer :
QuestionID : 1316 Subject Name Core Java
Q4. Members of a class specified as private are accessible only to the
methods of the class.
Correct Answer : T
Your Answer :
QuestionID : 1318 Subject Name Core Java
Q5. A static class method can be invoked by simply using the name of the
method alone.
Correct Answer : T
Your Answer :
QuestionID : 1326 Subject Name Core Java
Q6. A catch can have comma-separated multiple arguments.
Correct Answer : F
Your Answer :
QuestionID : 1348 Subject Name Core Java
Q7. A panel cannot be added to another panel.
Correct Answer : F
Your Answer :
QuestionID : 1365 Subject Name Core Java
Q8. If a frame uses a Grid layout manager and does not contain any panels,
then all the components within the frame are of the same width and height.
Correct Answer : T
Your Answer :
QuestionID : 1370 Subject Name Core Java
Q9. The constructor JRadioButton (String label, Icon icon) constructs a radio
button that is initially unselected.
Correct Answer : T
Your Answer :
QuestionID : 1381 Subject Name Core Java
Q10. The methods wait( ) and notify( ) are defined in
1. [Link]
2. [Link]
3. [Link]
4. [Link]
Correct Answer : 3
Your Answer :
QuestionID : 1387 Subject Name Core Java
Q11. A thread can make a second thread ineligible for execution by calling
the suspend( ) method on the second thread.
Correct Answer : F
Your Answer :
QuestionID : 9322 Subject Name Core Java
Q12. You need to read in lines of a laege text file containing tens of
megabytes of data.
Which of the following would be most suitable for reading such file
1. new FileInputStream("[Link]")
2. new InputStreamReader(new FileInputStream("[Link]"))
3. new BufferedReader(new FileInputStream("[Link]"))
4. new RandomAccessFile raf=new
RandomAccessFile("[Link]","+rw");
Correct Answer : 3
Your Answer :
QuestionID : 9332 Subject Name Core Java
Q13. Which is a dual state menu item?
1. Checkbox Menuitem
2. popup menuitem
3. submenu item
4. Menubar
Correct Answer : 1
Your Answer :
QuestionID : 9347 Subject Name Core Java
Q14. Which of the following may have null value?
1. collection
2. List
3. Map
4. Set
Correct Answer : 3
Your Answer :
QuestionID : 9358 Subject Name Core Java
Q15. Which of the following [Link] classes support internationalisation?
1. Locale
2. ResourceBundle
3. Country
4. Language
Correct Answer : 1
Your Answer :
QuestionID : 9366 Subject Name Core Java
Q16. Which of the following is not a wrapper class?
1. String
2. Boolean
3. Integer
4. Character
Correct Answer : 1
Your Answer :
QuestionID : 9473 Subject Name Core Java
Q17. Read the following code carefully
public abstract class AbstractClass
{
public AbstractClass()
{
[Link]("this is an abstract class constructor");
}
public void amethod()
{
[Link]("This is in the method in the abstract class");
}
}
1. Compiler error-abstract classes cannot have constructors.
2. Compiler error-the method AbstractClass does not have a valid return
type.
3. Compiler error-the class is pracically not an abstract class as it does not
have any unimplementd methods.
4. No compiler error-the class cannot be instantiated [Link] has to be
extended to an non-abstract [Link] constructors of the extended class will
call the constructor of the abstract class.
Correct Answer : 4
Your Answer :
QuestionID : 9519 Subject Name Core Java
Q18. When must the main class and the file name coincide?
1. When class is declared public
2. When the class is in a package
3. When the class is a friend class
4. Always
Correct Answer : 1
Your Answer :
QuestionID : 9564 Subject Name Core Java
Q19. 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 : 9570 Subject Name Core Java
Q20. Which of the following is not a wrapper class
1. String
2. Integer
3. Boolean
4. character
Correct Answer : 1
Your Answer :
QuestionID : 9589 Subject Name Core Java
Q21. In the following code,A and D will compile without any error.

[Link] sbl="abcd";
[Link] b = new Boolean("abcd");
[Link] b=255;
[Link] x=0x1234;
[Link] f1=1.2;
Correct Answer : F
Your Answer :
QuestionID : 9650 Subject Name Core Java
Q22. 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 :
QuestionID : 9651 Subject Name Core Java
Q23. class Test
{
Test(int i)
{
[Link]("Test("+i+")");
}
};
public class test1
{
static Test t1=new Test(1);
Test t2=new Test(2);
static Test t3=new Test(3);
public static void main(String[] args)
{
test1 t=new test1();
[Link]("Hello World!");
}
}
1. Test(1)
Test(2)
Test(3)
2. Test(3)
Test(2)
Test(1)
3. Test(2)
Test(1)
Test(3)
4. Test(1)
Test(3)
Test(2)
Correct Answer : 4
Your Answer :
QuestionID : 9653 Subject Name Core Java
Q24. Read this piece of code carefully

if("String".replace(`T`,`t`)=="String")
[Link]("equal");
else
[Link]("not equal");

1. the code will compile and print "equal"


2. the code will compile and print "not equal"
3. the code will cause compilation error
4. None of the above
Correct Answer : 1
Your Answer :
QuestionID : 9659 Subject Name Core Java
Q25. what is the class name of the exception thrown by an assertion
statement?
1. AssertionError
2. FailedAssertion
3. Error
4. RuntimeException
Correct Answer : 1
Your Answer :
QuestionID : 9665 Subject Name Core Java
Q26. Objects are always passed
1. By value
2. By reference
3. Either by val or by ref
4. By using pointers
Correct Answer : 2
Your Answer :
QuestionID : 9666 Subject Name Core Java
Q27. Given the class
//File:[Link]
public class Args{
public static void main(String[] args){
[Link](args[0]+" "+args[[Link]-1]);
}}
what would be the result of execution the following on the command line !
java Args In politics stupidity is not handicap
1. program will throw ArrayIndexOutofBoundException
2. program will print "In handicap"
3. program will print "java handicap"
4. program will print "Args handicap"
Correct Answer : 2
Your Answer :
QuestionID : 9791 Subject Name Core Java
Q28. Write down the modifier of a method that makes the method available
to all classes in the same package and to all the subclasses of this class.
1. private
2. protected
3. public
4. default
Correct Answer : 2
Your Answer :
QuestionID : 9796 Subject Name Core Java
Q29. 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 : 9827 Subject Name Core Java
Q30. What will happen if you compile/run this code?

1: public class Q1 extends Thread


2: {
3: public void run()
4: {
5: [Link]("Before start method");
6: [Link]();
7: [Link]("After stop method");
8: }
9:
10: public static void main(String[] args)
11: {
12: Q1 a = new Q1();
13: [Link]();
14: }
15: }
1. Compilation error at line 7.
2. Runtime exception at line 7.
3. Prints "Before start method" and "After stop method".
4. Prints "Before start method" only.
Correct Answer : 4
Your Answer :
QuestionID : 9846 Subject Name Core Java
Q31. JVM sets aside a special area of memory called String Constant Pool.
Correct Answer : T
Your Answer :
QuestionID : 9900 Subject Name Core Java
Q32. Abstract method can be defined in non abstract class.
Correct Answer : F
Your Answer :
QuestionID : 9935 Subject Name Core Java
Q33. 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 :
QuestionID : 9936 Subject Name Core Java
Q34. Does this code will compile?
class base
{
int x=10;
}
class sib1 extends base
{
int y=20;
}
class sib2 extends base
{
int z=30;
}
public class test
{
public static void main(String[] args)
{
base bs= new base();
sib1 a=new sib1();
sib2 b=new sib2();
a=b;
}
}
1. It will give error due to base reference compatibility
2. It will give runtime error
3. It will give compile time error due to incompatibility
4. Code will run smoothly
Correct Answer : 3
Your Answer :
QuestionID : 9951 Subject Name Core Java
Q35. HashTable can accept null key value pair.
Correct Answer : F
Your Answer :
QuestionID : 9988 Subject Name Core Java
Q36. which of the following statement correctly an interface ?
1. it`s a concrete class
2. it`s a supper class
3. it`s a type of abstract class
4. 1&2&3
Correct Answer : 3
Your Answer :
QuestionID : 10027 Subject Name Core Java
Q37. What command in the Java 2 SDK should be used to compile the
following code contained in a file called [Link]?public class
SmallProg { public static void main(String[] args)
{ [Link]("Good luck!"); }}
1. a. java SmallProg
2. b. javac SmallProg
3. c. java [Link]
4. d. javac [Link]
Correct Answer : 4
Your Answer :
QuestionID : 10033 Subject Name Core Java
Q38. What is the output of the following code?

1: int i = 45678;
2: int j = ~i;
3:
4: [Link](j);
1. Compilation error at line 2. ~ operator applicable to boolean values
only.
2. Prints 45677.
3. Prints -45677.
4. Prints -45679.
Correct Answer : 4
Your Answer :
QuestionID : 10053 Subject Name Core Java
Q39. A Monitor is an object that is used as mutually exclusive lock.
Correct Answer : T
Your Answer :
QuestionID : 10092 Subject Name Core Java
Q40. 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 :
QuestionID : 10113 Subject Name Core Java
Q41. What is the result of executing the following code, using the parameters
4 and 0:

public void divide(int a, int b) {

try {

int c = a / b;

} catch (Exception e) {

[Link]("Exception ");

} finally {
[Link]("Finally");

1. Prints out: Exception Finally


2. Prints out: Finally
3. Prints out: Exception
4. No output
Correct Answer : 1
Your Answer :
QuestionID : 10128 Subject Name Core Java
Q42. "drawString()" is method of graphics class.
Correct Answer : T
Your Answer :
QuestionID : 10133 Subject Name Core Java
Q43. A class can extend any no. of other classes.
Correct Answer : F
Your Answer :
QuestionID : 10149 Subject Name Core Java
Q44. What will be output of following

int tooSmall = Integer.MIN_VALUE - 1


1. 2147483647
2. -2147483648
3. Will give compile error
4. None of the above
Correct Answer : 1
Your Answer :
QuestionID : 10190 Subject Name Core Java
Q45. to ensure identical results are produced on all JVMs, the keyword
strictfp can be used to enforce strict behaviour for floating point arithmetic
1. enforcefp
2. strictfp
3. strictfloat
4. enforcefloat
Correct Answer : 2
Your Answer :
QuestionID : 10197 Subject Name Core Java
Q46. Volatile can be applied to
1. Static variable
2. Final variable
3. Both 1 & 2
4. None
Correct Answer : 3
Your Answer :
QuestionID : 10213 Subject Name Core Java
Q47. Given the following declaration,which expression returns the size of the
array,assuming the array has been initialized?
1. array[].length()
2. [Link]()
3. [Link]()
4. [Link]
Correct Answer : 4
Your Answer :
QuestionID : 10484 Subject Name Core Java
Q48. bind and rebind are methods of remote interface
Correct Answer : F
Your Answer :
QuestionID : 10498 Subject Name Core Java
Q49. inner classes are visible to other classes in the same package.
Correct Answer : F
Your Answer :
QuestionID : 11043 Subject Name Core Java
Q50. Applet class can be private,protected and public.
Correct Answer : F
Your Answer :

Common questions

Powered by AI

The `strictfp` keyword in Java enforces strict floating-point arithmetic, ensuring that floating-point calculations are consistent across all platforms. This ensures adherence to the IEEE-754 standard by preventing optimization discrepancies across varying hardware architectures, which might otherwise lead to small differences in calculation results.

The methods `wait()` and `notify()` are part of the `java.lang.Object` class, which allows any Java object to be used as a synchronization lock, facilitating inter-thread communication. This design ensures that every Java object has these basic concurrency capabilities, which is essential for building multi-threaded applications.

In Java, when a class is declared as public, it must be placed in a file named exactly as the class name with the `.java` extension. This requirement helps the Java compiler locate the source code for the class efficiently. Moreover, a public class is accessible from any other class, which enables broader interaction across different packages.

In Java, a catch block cannot have multiple arguments separated by commas. Catch blocks are designed to handle one exception type at a time. Multiple exceptions can be specified by using multiple catch blocks or a multi-catch block with a single parameter declared using the pipe symbol (|)

In Java, an abstract method cannot be defined in a non-abstract class because abstract methods must be implemented by a subclass. A non-abstract class implies it provides a complete implementation, and thus, it cannot have unimplemented (abstract) methods, maintaining consistency in class design.

The assignment `StringBuffer sbl="abcd";` is incorrect because a `StringBuffer` is not directly initialized using a string literal. Instead, it must be instantiated with `new`, like `StringBuffer sbl = new StringBuffer("abcd");`, because `StringBuffer` is a class and must follow object instantiation syntax.

This code will compile, but it will not produce a meaningful comparison. The `replace` method in Java performs the character substitution correctly, changing the string to a new instance. However, since the `==` operator checks for object reference equality, not content, the comparison `"String".replace('T','t')=="String"` would evaluate to false. In this case, the output will be 'not equal'.

Members of a Java class declared as private can only be accessed within the methods of the same class. They are not accessible outside the class or by subclasses, thus encapsulating the data and ensuring data hiding.

The statement 'float x = 123.4;' is invalid due to the floating-point literal being treated as a double by default in Java. To correct it, a float literal should be suffixed with 'f', making it 'float x = 123.4f;'.

In Java, instance variables of a class have default values based on their types (e.g., 0 for int, null for objects, false for booleans). In contrast, local variables do not have a default value and must be explicitly initialized before they are used; otherwise, the compiler will throw an error.

You might also like