Simple Java Quiz

Simple Java Quiz

10 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which methods can access to private attributes of a class

  1. A. Only Static methods of the same class
  2. B. Only instances of the same class
  3. C. Only methods those defined in the same class
  4. D. Only classes available in the same package.
Question 2 Multiple Choice (Single Answer)

Which of the following statements is false about objects

  1. A. An instance of a class is an object
  2. C. Object is the super class of all other classes
  3. D. Objects do not permit encapsulation
Question 3 Multiple Choice (Single Answer)

What is an aggregate object?

  1. A. An object with only primitive attributes
  2. C. An instance which has other objects
  3. D. None of the above
Question 4 Multiple Choice (Single Answer)

What is the meaning of the return data type void?

  1. B. void returns no data type.
  2. C. void is not supported in Java
  3. D. None of the above
Question 5 Multiple Choice (Single Answer)

A class can have many methods with the same name as long as the number of parameters or type of parameters is different. This OOP concept is known as

  1. A. Method Invocating
  2. B. Method Overriding
  3. C. Method Labeling
  4. D. Method Overloading
Question 6 Multiple Choice (Single Answer)

After the following code fragment, what is the value in fname?String str;int fname;str = ";Foolish boy.";fname = str.indexOf("fool");

  1. A. 0
  2. B. 2
  3. C. -1
  4. D. 4
Question 7 Multiple Choice (Single Answer)

The code snippetif( "Welcome".trim() == "Welcome".trim() )System.out.println("Equal");elseSystem.out.println("Not Equal");will

  1. A. Compile and display “Equal”
  2. B. Compile and display “Not Equal”
  3. C. Cause a compiler error
  4. D. Compile and display NULL
Question 8 Multiple Choice (Single Answer)

Which of the following is not a return type?

  1. A. boolean
  2. B. void
  3. C. public
  4. D. Button
Question 9 Multiple Choice (Single Answer)

The class java.lang.Exception is

  1. A. protected
  2. B. extends Throwable
  3. C. implements Throwable
  4. D. serializable
Question 10 Multiple Choice (Single Answer)

Consider the following code snippet. What will be assigned to the variable fourthChar, if the code is executed? String str = new String(“Java”); char fourthChar = str.charAt(4);

  1. A. ‘a’
  2. B. ‘v’
  3. C. throws StringIndexOutofBoundsException
  4. D. null characater