Java Skill Assessment Test

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By R2international
R
R2international
Community Contributor
Quizzes Created: 1 | Total Attempts: 7,551
Questions: 23 | Attempts: 7,560

SettingsSettingsSettings
Java Skill Assessment Test - Quiz

This test will measure the applicants knowledge and competency in the technical field of Java development and programming


Questions and Answers
  • 1. 

    What is the size of a Char?

    • A.

      4 bits

    • B.

      7 bits

    • C.

      8 bits

    • D.

      16 bits

    Correct Answer
    D. 16 bits
    Explanation
    The size of a Char is 16 bits. This means that a Char data type can store values ranging from -32,768 to 32,767.

    Rate this question:

  • 2. 

    A class cannot be declared

    • A.

      Static

    • B.

      Private

    • C.

      Default

    Correct Answer
    B. Private
    Explanation
    A class cannot be declared as private because the access modifier "private" restricts the visibility of members to only within the same class. However, a class needs to be accessible outside of its own class in order to be used by other classes or objects. Therefore, a class can be declared as static or default, but not as private.

    Rate this question:

  • 3. 

    Following code will result in: int a = 3.5;

    • A.

      Compilation error

    • B.

      Runtime error

    • C.

      A being 3.5

    • D.

      A being 3

    Correct Answer
    A. Compilation error
    Explanation
    The code will result in a compilation error because the variable "a" is declared as an integer, but it is being assigned a value of 3.5, which is a floating-point number. In Java, you cannot assign a floating-point value to an integer variable without explicitly casting it.

    Rate this question:

  • 4. 

    Following code will result in: int a1 = 5; double a2 = (float)a1;

    • A.

      Compilation error

    • B.

      Runtime error

    • C.

      No errors

    Correct Answer
    C. No errors
    Explanation
    The given code will not result in any errors. It declares an integer variable "a1" with a value of 5 and a double variable "a2" which is assigned the value of "a1" after casting it to a float. Since the casting is allowed and there are no other issues with the code, it will compile and run without any errors.

    Rate this question:

  • 5. 

    Following code will result in: int a = 9/0;

    • A.

      Compilation error: Divisions must be in a try block

    • B.

      Compilation error: DivideByZeroException

    • C.

      Runtime Exception

    • D.

      No Error: a is NaN

    Correct Answer
    C. Runtime Exception
    Explanation
    The code will result in a Runtime Exception because it is attempting to divide 9 by 0, which is not possible and will cause an ArithmeticException to be thrown at runtime.

    Rate this question:

  • 6. 

    Following code will result in: float a = 9/0;

    • A.

      Compilation error: Divisions must be in a try block

    • B.

      Compilation error: DivideByZeroException

    • C.

      Runtime Exception

    • D.

      No Error: a is NaN

    Correct Answer
    D. No Error: a is NaN
    Explanation
    The code will not result in a compilation error or a runtime exception. Instead, it will assign the value NaN (Not a Number) to the variable 'a'. This is because dividing any number by zero in floating-point arithmetic results in NaN.

    Rate this question:

  • 7. 

    A class can be transient

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    A class cannot be transient. The "transient" keyword in programming languages is used to indicate that a variable should not be serialized, meaning it will not be included when the object is converted into a stream of bytes. However, the "transient" keyword cannot be applied to a class itself. It can only be used with variables within a class. Therefore, the correct answer is False.

    Rate this question:

  • 8. 

    Following code will result in: class A { int b = 1; public static void main(String [] args) { System.out.println("b is " + b); }}

    • A.

      Compilation error

    • B.

      Runtime Error

    • C.

      Runtime Exception

    • D.

      Output of b is 1

    Correct Answer
    A. Compilation error
    Explanation
    The code will result in a compilation error because the variable "b" is an instance variable and cannot be accessed directly from a static method (main method). To access the instance variable, an object of class A needs to be created.

    Rate this question:

  • 9. 

    Following code will result in: class A { public static void main(String [] args) {B b = new A(); }} class B extends A {}

    • A.

      Compile error

    • B.

      Runtime Exception

    • C.

      No error

    Correct Answer
    A. Compile error
    Explanation
    The code will result in a compile error because it is trying to create an instance of class A using the constructor of class B. Since class B extends class A, it is possible to create an instance of class B using the constructor of class A, but not the other way around. Therefore, the code is not valid and will not compile.

    Rate this question:

  • 10. 

    Following code will result in: class A { public static void main(String [] args) {A a = new B(); }} class B extends A {}

    • A.

      Compiler error

    • B.

      Runtime Exception

    • C.

      No errors

    Correct Answer
    C. No errors
    Explanation
    The given code will not result in any errors because class B is a subclass of class A, so it is valid to assign an instance of B to a variable of type A. Therefore, the code will compile successfully and run without any issues.

    Rate this question:

  • 11. 

    Methods that are marked protected can be called in any subclass of that class.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Protected methods in a class can be accessed by any subclass of that class. This means that even if the subclass is in a different package or module, it can still call the protected method. This is because protected access allows for inheritance and provides a way for subclasses to access and modify the behavior of the superclass. Therefore, the given answer, which states that protected methods can be called in any subclass of the class, is true.

    Rate this question:

  • 12. 

    An abstract class can have non-abstract methods.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    An abstract class can have non-abstract methods because an abstract class is a class that cannot be instantiated and is meant to be extended by other classes. It can contain both abstract and non-abstract methods. Non-abstract methods in an abstract class can have a defined implementation, allowing the abstract class to provide common functionality to its subclasses. Subclasses that extend the abstract class can inherit and use these non-abstract methods without needing to redefine them. Therefore, it is true that an abstract class can have non-abstract methods.

    Rate this question:

  • 13. 

    Java keywords are written in lowercase as well as uppercase

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    Java keywords are written in lowercase only. This is because Java is case-sensitive, meaning that uppercase and lowercase letters are treated as different characters. Therefore, using uppercase letters in keywords would result in a compilation error.

    Rate this question:

  • 14. 

    What is an instanceof

    • A.

      A methods in object

    • B.

      An operator and keyword

    Correct Answer
    B. An operator and keyword
    Explanation
    The correct answer is "An operator and keyword". The instanceof operator is used to check if an object belongs to a certain class or implements a certain interface. It returns true if the object is an instance of the specified class or interface, and false otherwise. It is a keyword in Java that is used in conjunction with the operator to perform this check.

    Rate this question:

  • 15. 

    Primitive datatypes are allocated on a stack.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Primitive datatypes are allocated on a stack because they are small and have a fixed size. The stack is a region of memory that is used for local variables and function calls. When a primitive datatype is declared, memory is allocated on the stack to store its value. This memory is automatically freed when the variable goes out of scope. This is in contrast to objects, which are allocated on the heap and require manual memory management.

    Rate this question:

  • 16. 

    Can you compare a boolean to an integer?

    • A.

      Yes

    • B.

      No

    Correct Answer
    B. No
    Explanation
    A boolean represents a binary value, either true or false, while an integer represents a numerical value. These two types are not directly comparable as they have different representations and purposes. In most programming languages, attempting to compare a boolean to an integer would result in a type error. Therefore, the correct answer is "No".

    Rate this question:

  • 17. 

    Integer a = new Integer(2); Integer b = new Integer(2); What happens when you do if (a==b)?

    • A.

      Compiler error

    • B.

      Runtime Exception

    • C.

      True

    • D.

      False

    Correct Answer
    D. False
    Explanation
    When comparing two objects using the == operator, it checks if the two objects are referring to the same memory location. In this case, since both objects a and b are created using the new keyword, they are stored in different memory locations even though they have the same value. Therefore, the condition (a==b) evaluates to false.

    Rate this question:

  • 18. 

    Synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The explanation for the given correct answer is that the "synchronized" keyword in Java is used to ensure that only one thread can access a block of code or an object at a time. It grabs an object lock before executing the synchronized code, preventing other threads from accessing it simultaneously. This helps in preventing race conditions and maintaining data integrity in multi-threaded environments. Therefore, the statement "Synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution" is true.

    Rate this question:

  • 19. 

    The default statement of a switch is always executed

    • A.

      By marking it private

    • B.

      By marking it volatile

    • C.

      By marking it transient

    • D.

      You can not.

    Correct Answer
    C. By marking it transient
  • 20. 

    Which one does not extend java.lang.Number

    • A.

      Integer

    • B.

      Boolean

    • C.

      Character

    • D.

      Long

    • E.

      Short

    Correct Answer(s)
    B. Boolean
    C. Character
    Explanation
    The correct answer is Boolean and Character because they do not extend the java.lang.Number class. The java.lang.Number class is the superclass of all the numeric wrapper classes in Java, such as Integer, Long, and Short, which means they extend the Number class. However, Boolean and Character are not numeric types and thus do not extend the Number class.

    Rate this question:

  • 21. 

    What is default layout manager for panels and applets?

    • A.

      Flowlayout

    • B.

      Gridlayout

    • C.

      BorderLayout

    Correct Answer
    A. Flowlayout
    Explanation
    The default layout manager for panels and applets is FlowLayout. FlowLayout arranges components in a left-to-right flow, wrapping them to the next line if there is not enough space horizontally. This layout manager is commonly used when you want components to be displayed in a simple, linear fashion.

    Rate this question:

  • 22. 

    Which of the following statements are true?

    • A.

      When you construct an instance of File, if you do not use the filenaming semantics of the local machine, the constructor will throw an IOException.

    • B.

      When you construct an instance of File, if the corresponding file does not exist on the local file system, one will be created.

    • C.

      When an instance of File is garbage collected, the corresponding file on the local file system is deleted.

    • D.

      None of the above

    Correct Answer(s)
    A. When you construct an instance of File, if you do not use the filenaming semantics of the local machine, the constructor will throw an IOException.
    B. When you construct an instance of File, if the corresponding file does not exist on the local file system, one will be created.
    C. When an instance of File is garbage collected, the corresponding file on the local file system is deleted.
    Explanation
    The first statement is true because if the filenaming semantics of the local machine are not used when constructing an instance of File, the constructor will throw an IOException. The second statement is also true because if the corresponding file does not exist on the local file system, it will be created when constructing an instance of File. However, the third statement is false. When an instance of File is garbage collected, it does not automatically delete the corresponding file on the local file system.

    Rate this question:

  • 23. 

    You execute the code below in an empty directory. What is the result? File f1 = new File("dirname"); File f2 = new File(f1, "filename");

    • A.

      A new directory called dirname is created in the current working directory

    • B.

      A new directory called dirname is created in the current working directory. A new file called filename is created in directory dirname

    • C.

      A new directory called dirname and a new file called filename are created, both in the current working directory

    • D.

      A new file called filename is created in the current working directory

    • E.

      No directory is created, and no file is created

    Correct Answer
    E. No directory is created, and no file is created
    Explanation
    The code creates two File objects, f1 and f2. The constructor for f1 takes a string parameter "dirname", which represents a directory name. However, the code does not actually create a directory or a file. It simply creates the File objects with the given names. Therefore, the correct answer is that no directory is created, and no file is created.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 17, 2009
    Quiz Created by
    R2international
Back to Top Back to top
Advertisement