NEW
Font size
WorksheetsAdvanced MCQs on OOPs and FileInputOutput Stream
Total questions: 30
Worksheet time: 30mins
Which of the following statements about inheritance is false?
A subclass can access protected members of its superclass.
A subclass can override private methods of its superclass.
A subclass can inherit final variables from superclass.
A subclass constructor always calls the superclass constructor.
If a superclass constructor takes parameters, what must the subclass constructor do?
It must call super() with arguments explicitly.
It can skip calling super().
It must override all superclass methods.
It must be declared abstract.
What will happen if a subclass defines a field with the same name as in its superclass?
Causes compile-time error
Field hiding occurs
Method overriding occurs
The superclass variable is replaced
What is true about method overloading?
It depends on the return type only.
It depends on the method name and parameter list.
It depends only on the method name.
It depends on the access modifier.
Which of the following cannot be abstract?
Class
Method
Constructor
Interface
When is a constructor called during inheritance?
After the child class constructor
Before the child class constructor
Randomly
Only when explicitly called
What will happen if an abstract class has no abstract methods?
It cannot be instantiated.
It can be instantiated.
It throws a compile-time error.
It must have at least one abstract method.
What happens when a subclass does not override an abstract method from its superclass?
Compilation succeeds
The subclass must be declared abstract
The method becomes private
The subclass can still be instantiated
What happens when two classes have the same method and a third class inherits both (via interfaces)?
Compilation error unless the method is overridden.
Both methods execute.
JVM picks one randomly.
It’s not allowed in Java.
Which concept allows a class to have multiple methods with the same name but different signatures?
Overriding
Overloading
Encapsulation
Abstraction
Which of these exceptions is unchecked?
IOException
SQLException
NullPointerException
FileNotFoundException
Can a finally block modify the value returned by a try block?
Yes, the finally block can change the return value.
No, it always executes after return.
Yes, but only for primitive types.
No, it executes before return.
Which of the following is true about exception handling hierarchy?
Throwable → Exception → RuntimeException
Exception → Throwable → RuntimeException
Throwable → Error → Exception
Exception → Error → Throwable
What happens if an exception is thrown inside a catch block?
It is ignored.
It must be handled by another catch block or the method.
JVM stops immediately.
It goes to the finally block only.
Can a try block exist without a catch block?
No
Yes, if followed by finally
Yes, if inside another try
Yes, always
Which statement is true about checked exceptions?
They occur at runtime.
They must be caught or declared using throws.
They cannot be propagated.
They are subclasses of Error.
What happens when an exception occurs and is not handled?
Program resumes execution normally.
JVM terminates the program.
Exception is ignored.
Compiler adds a default catch block.
Which of the following cannot be caught using a catch block?
IOException
ArithmeticException
StackOverflowError
RuntimeException
What happens if two packages contain classes with the same name?
Compilation error
Use of fully qualified name is required
Both are imported automatically
One overrides the other
Can we import a subpackage automatically by importing the parent package?
Yes
No
Which package is imported automatically in all Java programs?
java.util
java.io
java.lang
java.net
What is the main advantage of using packages?
Slows down compilation
Helps organize classes and avoid naming conflicts
Increases code size
Makes code platform-dependent
What happens when FileReader is used on a binary file?
Works fine
May lead to data corruption or unreadable output
Reads all data correctly
Throws IOException always
Which stream reads raw bytes from a file?
FileReader
FileInputStream
BufferedReader
PrintWriter
What happens if you write to a closed stream?
IOException is thrown
Data is buffered
It automatically reopens
It writes nothing silently
Which of these statements about BufferedReader is true?
It reads character data efficiently using buffering.
It reads binary data.
It cannot be chained with other readers.
It is slower than FileReader.
What is the difference between FileWriter and BufferedWriter?
BufferedWriter writes faster by reducing disk access.
FileWriter is used only for binary data.
BufferedWriter can’t wrap FileWriter.
FileWriter automatically adds buffering.
What will happen if a file doesn’t exist when FileInputStream is created?
A new file is created.
IOException is thrown.
Returns null.
File is ignored.
Which class is used for reading both bytes and characters efficiently?
DataInputStream
RandomAccessFile
FileReader
BufferedReader
What happens when two FileOutputStreams write to the same file simultaneously?
The data is merged automatically.
The file content may get corrupted.
Both streams write alternately.
The JVM prevents concurrent access.
