Java QuizBy digitalcollegelibrary.com / 21 March 2024 In this Java Language Quiz section - every Question Carries 2 Marks. If any question is wrong then two marks will be deducted.Note: - Fill the information Correctly to get Certified. Java Quiz 1 / 50 Which of the following is NOT a primitive data type in Java? int float string boolean 2 / 50 Which keyword is used to define a subclass in Java? parent base extend subclass 3 / 50 What does the static keyword mean in Java? The variable or method belongs to the class, not instances of the class. The variable or method can be accessed only within the same package. The variable or method cannot be modified after initialization. The variable or method cannot be accessed by any other class. 4 / 50 Which of the following is a correct way to declare a constant in Java? constant int PI = 3.14; final double PI = 3.14; const double PI = 3.14; double PI = 3.14; 5 / 50 What does the super keyword do in Java? It refers to the superclass of the current class. It calls the superclass constructor. It refers to the object itself. It is used to access static members of a class. 6 / 50 What is the correct way to declare a constant variable in Java? constant int MY_CONSTANT = 10; final int MY_CONSTANT = 10; static final int MY_CONSTANT = 10; final static int MY_CONSTANT = 10; 7 / 50 Which of the following is NOT a valid Java identifier? _variableName $variableName 1variableName variableName 8 / 50 What is the purpose of the break statement in Java? To exit from the current loop or switch statement To skip the current iteration of a loop and continue with the next iteration To execute a block of code repeatedly To define a case in a switch statement 9 / 50 What is the result of 10 % 3 in Java? 3 1 2 0 10 / 50 Which of the following is true about Java interfaces? An interface can have method implementations. A class can implement multiple interfaces. An interface can extend multiple classes. An interface can have instance variables. 11 / 50 What does the compareTo() method of the Comparable interface return? boolean int void String 12 / 50 What does the finally block in a Java try-catch-finally statement do? It is executed if an exception is thrown. It is executed after the try or catch block, regardless of whether an exception is thrown or not. It is used to handle exceptions. It is used to declare methods that may throw exceptions. 13 / 50 Which of the following access modifiers restricts access the most in Java? public private protected default (package-private) 14 / 50 What is the purpose of the super() keyword in Java? It calls the superclass constructor. It is used to access superclass methods and variables. It is used to create an object of the superclass. It is used to define a superclass. 15 / 50 Which of the following statements is true about static methods in Java? Static methods can access instance variables directly. Static methods cannot be overridden in subclasses. Static methods are called using object references. Static methods belong to the class rather than the instances of the class. 16 / 50 What does the instanceof operator do in Java? It checks if two objects are the same. It checks if an object is an instance of a particular class or interface. It checks if an object is null. It checks if two objects are equal. 17 / 50 What is the purpose of the this keyword in Java? It is used to call a superclass constructor. It is used to access instance variables and methods of the current object. It is used to create a copy of an object. It is used to check if an object is null. 18 / 50 Which of the following statements is true about Java packages? A package can contain only classes but not interfaces. A package can be defined inside a class. A package can be imported using the "import" keyword. A package cannot contain sub-packages. 19 / 50 Which of the following statements is true about Java interfaces? An interface can extend multiple classes. An interface can contain constructors. An interface can have method implementations. A class implementing an interface must implement all its methods. 20 / 50 Which keyword is used to prevent a method from being overridden in Java? final static abstract override 21 / 50 What does the super keyword refer to in Java? It refers to the superclass of the current class. It refers to the current instance of the class. It refers to the subclass of the current class. It refers to the parent class of the current class. 22 / 50 What is the default value of a boolean variable in Java? true false 0 null 23 / 50 What is the purpose of the toString() method in Java? To convert a string to uppercase. To convert an object to a string representation. To concatenate two strings. To parse a string into primitive data types. 24 / 50 Which of the following is NOT a valid access modifier in Java? public private protected friendly 25 / 50 Which of the following is NOT a valid access modifier in Java? public private protected friendly 26 / 50 What is the difference between == and .equals() method in Java? They both check for reference equality. They both check for value equality. == checks for reference equality while .equals() checks for value equality. == checks for value equality while .equals() checks for reference equality. 27 / 50 What is the maximum value that an int variable can hold in Java? 2^31 - 1 2^32 - 1 2^63 - 1 2^64 - 1 28 / 50 Which of the following is used to create an object in Java? new class object create 29 / 50 What is the purpose of the instanceof operator in Java? It checks if two objects are the same instance. It checks if an object belongs to a particular class or interface. It checks if an object is null. It checks if an object is empty. 30 / 50 Which of the following statements is true about Java's ArrayList and LinkedList classes? ArrayList is faster than LinkedList for insertion and deletion operations. LinkedList is implemented using an array data structure. ArrayList is more memory-efficient than LinkedList. LinkedList is faster than ArrayList for insertion and deletion operations. 31 / 50 What does the static keyword mean when applied to a method in Java? The method can be called without creating an instance of the class. The method cannot be called. The method can only be accessed from within the same class. The method can only be accessed from outside the class. 32 / 50 Which of the following is true about method overloading in Java? Methods must have the same name but different return types. Methods must have the same name and same return type. Methods must have different names and different return types. Methods must have the same name but different parameter lists. 33 / 50 What is the purpose of the this keyword in Java? It refers to the superclass of the current class. It refers to the subclass of the current class. It refers to the current instance of the class. It refers to the parent class of the current class. 34 / 50 Which of the following statements about Java packages is false? Packages help organize Java code into namespaces. Packages can be nested within other packages. A class can belong to only one package. Packages provide access protection and namespace management. 35 / 50 What does the Math.random() method in Java return? A random integer between 0 and 100. A random double between 0.0 (inclusive) and 1.0 (exclusive). A random boolean value. A random long value. 36 / 50 Which of the following is NOT a valid type of loop in Java? for while do-while foreach 37 / 50 What is the purpose of the static keyword when applied to a variable in Java? It indicates that the variable can only be accessed within the same class. It indicates that the variable is shared among all instances of the class. It indicates that the variable cannot be modified. It indicates that the variable is initialized with a default value. 38 / 50 Which of the following is NOT a primitive data type in Java? int float string double 39 / 50 Which of the following is true about Java constructors? Constructors can return values. Constructors cannot be overloaded. Constructors are called explicitly using the new keyword. Constructors have the same name as the class. 40 / 50 Which of the following is true about Java's HashSet class? Elements in a "HashSet" are ordered. Elements in a "HashSet" are stored based on their insertion order. "HashSet" allows duplicate elements. "HashSet" guarantees constant-time performance for basic operations. 41 / 50 Which of the following is NOT a valid Java annotation? @Override @NotNull @Final @Deprecated 42 / 50 Which of the following modifiers makes a method or variable accessible only within its own package? private protected default public 43 / 50 What does the StringBuffer class in Java provide that String does not? Mutable strings Immutability More efficient memory usage Less overhead 44 / 50 Which keyword is used to create an instance of a class in Java? create new instance this 45 / 50 Which of the following statements about Java arrays is true? Arrays can contain elements of different data types. Arrays automatically resize when elements are added or removed. Arrays in Java are always dynamically allocated. The length of an array can be changed after it is created. 46 / 50 Which of the following is true about Java's HashMap class? "HashMap" maintains the order of elements based on their insertion order. "HashMap" allows duplicate keys but not duplicate values. "HashMap" is synchronized by default. "HashMap" guarantees constant-time performance for basic operations. 47 / 50 Which of the following is true about Java's StringBuilder class? "StringBuilder" is synchronized. "StringBuilder" is immutable. "StringBuilder" is not thread-safe. "StringBuilder" does not have a toString() method. 48 / 50 Which of the following access modifiers allows a member to be accessed only within its own class and package? private protected public default 49 / 50 Which of the following statements is true about Java's LinkedList class? "LinkedList" allows random access to its elements. "LinkedList" is a synchronized collection. "LinkedList" allows duplicate elements. "LinkedList" is more memory-efficient than arrays. 50 / 50 Which of the following statements about Java's HashSet class is true? "HashSet" allows duplicate elements. Elements in a "HashSet" are ordered based on their insertion order. "HashSet" is synchronized by default. "HashSet" allows null elements. Your score isThe average score is 76% 0% Restart quiz