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