Alien head

Simple Java Quiz

Description: Simple Java Quiz
Number of Questions: 10
Created by:
Tags: java

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.

Answer: 3

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

Answer: 3

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

Answer: 2

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

Answer: 1

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

Answer: 4

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

Answer: 3

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

Answer: 1

Which of the following is not a return type?

  1. A. boolean

  2. B. void

  3. C. public

  4. D. Button

Answer: 3

The class java.lang.Exception is

  1. A. protected

  2. B. extends Throwable

  3. C. implements Throwable

  4. D. serializable

Answer: 2

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

Answer: 3
+ View questions