50 MCQ on Advance Object Oriented Programing

  1. Which of the following is not a valid Java variable name?
    1. _myVar
    2. myVar1
    3. 1myVar
    4. MYVAR
  2. What is the result of the following Java expression: (5 > 3) &amp &amp (4 &lt 6)?
    1. true
    2. false
    3. compile error
    4. runtime error
  3. Which of the following is not a valid Java control structure?
    1. if-else
    2. switch-case
    3. do-while
    4. until-loop
  4. What is the output of the following Java code?
    int[][] myArray = {{1, 2), (3, 4)};
    System.out.println(myArray[1][0]);
    1. 1
    2. 2
    3. 3
    4. 4
  5. What is the result of the following Java expression: "Hello " + "World"?
    1. "Hello World"
    2. "HelloWorld"
    3. “WorldHello”
    4. Compile error
  6. What is the result of the following Java expression: 5 % 2?
    1. 2
    2. 3
    3. 0.5
    4. 1
  7. Which keyword is used to create an object of a class in Java?
    1. new
    2. class
    3. object
    4. this
  8. Which of the following is a default constructor in Java?
    1. Parameterized constructor
    2. Private constructor
    3. non-parameterized constructor
    4. Static constructor
  9. What is the purpose of method overloading in Java?
    1. To create multiple instances of a method with the same name within a class
    2. To override a method inherited from a superclass
    3. To create new data types in Java
    4. To access a private method outside of its class
  10. Which of the following is not a wrapper class in Java?
    1. Integer
    2. Float
    3. Double
    4. Array
  11. Which of the following is true about constructors in Java?
    1. A class can have multiple constructors with the same signature
    2. A constructor can have a return type
    3. A constructor can be inherited from a superclass
    4. A constructor can be declared as private
  12. What is the purpose of the toString() method in Java?
    1. To convert an object to a string
    2. To compare two objects for equality
    3. To convert a string to an object
    4. To create a copy of an object
  13. Which of the following is not a method in the Object class in Java?
    1. equals()
    2. getClass()
    3. hashCode()
    4. length()
  14. Which of the following is a valid identifier for a Java class?
    1. 123class
    2. _MyClass
    3. MyClass$
    4. My-class
  15. What is the purpose of the finalize() method in Java?
    1. To initialize an object of a class
    2. To free up system resources
    3. To destroy an object of a class
    4. To set the default value of a class variable
  16. Which of the following is not a valid access specifier in Java?
    1. Public
    2. Private
    3. Protected
    4. package
  17. Which of the following is true about concrete methods in an abstract class?
    1. They must be declared as abstract.
    2. They cannot be overridden in a subclass.
    3. They can be overridden in a subclass.
    4. They must be declared as private.
  18. Which keyword is used to declare a package in Java?
    1. package
    2. import
    3. class
    4. public
  19. Which of the following is true about packages in Java?
    1. Packages can only contain classes
    2. Packages must be imported before they can be used.
    3. Packages can be nested inside other packages.
    4. Packages are not supported in Java.
  20. Which of the following is true about the default package in Java?
    1. It is a reserved keyword in Java.
    2. It contains all the classes that are not in any package.
    3. It cannot be imported.
    4. It is automatically imported in every Java program.
  21. Which of the following is the correct syntax to import a package in Java?
    1. import package_name;
    2. import package_name.class_name;
    3. import package_name.";
    4. import class_name.package_name;
  22. Which keyword is used to declare an interface in Java?
    1. interface
    2. extends
    3. abstract
    4. implements
  23. Which of the following is true about interfaces in Java?
    1. They can have instance variables.
    2. They can be instantiated.
    3. They can have constructors.
    4. They can only have abstract methods.
  24. Which of the following is true about implementing interfaces in Java?
    1. A class can implement multiple interfaces.
    2. A class can only implement one interface.
    3. An interface can implement another interface.
    4. An interface cannot be implemented by a class.
  25. Which of the following is not a valid access specifier for methods in an interface?
    1. Public
    2. Private
    3. Protected
    4. default (package-private)
  26. Which keyword is used to throw an exception in Java?
    1. Throw
    2. Try
    3. Catch
    4. Finally
  27. Which of the following is a checked exception in Java?
    1. NullPointerException
    2. ArithmeticException
    3. ArrayIndexOutOfBoundsException
    4. FileNotFoundException
  28. Which of the following is an unchecked exception in Java?
    1. IOException
    2. RuntimeException
    3. ClassNotFoundException
    4. SQLException
  29. Which keyword is used to handle multiple exceptions in Java?
    1. Catch
    2. Try
    3. Finally
    4. throw
  30. Which of the following is not a type of exception in Java?
    1. Error
    2. RuntimeException
    3. Exception
    4. InterfaceException
  31. What is a thread in Java?
    1. A method for running multiple programs at once
    2. A block of code that can be executed concurrently with other blocks
    3. A class that represents a user interface element
    4. A tool for debugging code execution
  32. What is the purpose of the synchronized keyword in Java?
    1. To prevent multiple threads from executing a block of code at the same time
    2. To force multiple threads to execute a block of code at the same time
    3. To create a new thread for executing code
    4. To stop the execution of a thread
  33. What is a deadlock in Java threading?
    1. A situation where multiple threads are waiting for each other to finish executing
    2. A situation where a thread has finished executing but is not terminated
    3. A situation where a thread is running for too long and causing performance issues
    4. A situation where a thread is terminated before finishing its execution
  34. What is a race condition in Java threading?
    1. A situation where multiple threads are accessing and modifying the same data concurrently,
    2. A situation where a thread is terminated before finishing its execution
    3. A situation where a thread has finished executing but is not terminated
    4. A situation where a thread is running for too long and causing performance issues File Handling and Collections Framework
  35. Which of the following classes is used to read data from a file in Java?
    1. FileWriter
    2. FileReader
    3. InputStream
    4. OutputStream
  36. Which of the following methods is used to write data to a file in Java?
    1. write()
    2. read()
    3. close()
    4. flush()
  37. Which of the following classes is used to write data to a file in Java?
    1. FileWriter
    2. FileReader
    3. InputStream
    4. OutputStream
  38. Which of the following methods is used to read a line of text from a file in Java?
    1. readLine()
    2. readChar()
    3. read()
    4. write()
  39. Which of the following methods is used to create a new file in Java?
    1. createFile()
    2. newFile()
    3. makeFile()
    4. fileCreate()
  40. Which of the following classes is used to represent a file or directory path in Java?
    1. File
    2. Path
    3. Directory
    4. Folder
  41. Which of the following methods is used to check if a file exists in Java?
    1. exists()
    2. isFile()
    3. isDirectory()
    4. both A and B
  42. Which of the following methods is used to delete a file in Java?
    1. delete()
    2. remove()
    3. erase()
    4. clear()
  43. Which of the following classes is used to write binary data to a file in Java?
    1. FileWriter
    2. FileReader
    3. DataOutputStream
    4. DataInputStream
  44. Which of the following methods is used to append data to an existing file in Java?
    1. Append()
    2. Add()
    3. Insert()
    4. Concat()
  45. Which of the following interfaces is used to represent an ordered collection of elements in java?
    1. List
    2. Set
    3. Map
    4. Queue
  46. Which of the following interfaces is used to represent an unordered collection of elements in Java?
    1. List
    2. Set
    3. Map
    4. Queue
  47. Which of the following interfaces is used to represent a collection of key-value pairs in Java?
    1. List
    2. Set
    3. Map
    4. Queue
  48. Which of the following interfaces is used to represent a collection that allows duplicates and preserves insertion order in Java?
    1. HashSet
    2. TreeSet
    3. LinkedHashSet
    4. HashMap
  49. Which of the following methods is used to add an element to a collection in Java?
    1. add()
    2. remove()
    3. clear()
    4. size()
  50. which of the following methods is used to remove an element from a collection in java?
    1. add()
    2. remove()
    3. clear()
    4. size()

Comments