BTech Semester III OOPJ Question Bank
BTech Semester III OOPJ Question Bank
Write a Java method for computing the first n terms of Fibonacci sequence. Define method
main taking value of n a command line argument and calling the method.
Unit 3 – Inheritance and Interfaces
Define classes to appropriately represent the class hierarchy as shown in the above figure. Use
constructors for both classes and display Salary for a particular Employee.
Define a class Train representing the following members:
- Train Number
- Source
- Destination
- Journey Date
- Capacity
Methods
- Initialize members
- Input train data
- Display data
Write a Java program to test Train class
Define a class Bank Account to represent the following members:
Data Members
- Account Number
- Name of Depositor
- Account Type
- Balance Amount
Member Functions
- Initialize members
- Deposit Amount
- Withdraw Amount
- Display Balance
Write a Java program to test the BankAccount class for 5 customers.
Unit 5 – Multithreading,
What are the two ways to create Threads in Java? Write a multithreaded program to explain the
use of join() method.
Write a complete multi threaded program to meet following requirements for producer-
consumer threads:
- Three threads – one producer and two consumers to be instantiated in the method main.
- At a time, the producer produces one integer information along with consumer_id to represent
id of a consumer that will consume produced information.
- Information and consumer_id are stored in a shared buffer.
- The information produced is to be consumed by appropriate consumer only, as specified by
the producer.
- The producer thread produces total 6 information.
Unit 5 - IO
True/False
A protected member of a class can be accessed from its derived class.
An abstract class cannot have non-abstract methods.
A class which is implementing an interface must implement all the methods of the
interface.
A finally block can be executed before the catch block but after the try block.
Can 8-byte long data type be automatically type cast to 4-byte float data type.
Private constructors ensures multiple instances of a class exist at any point of
time.
Garbage collection is manual process in Java.
The modulus operator (%) in Java can be used only with variables of integer type.
A static method can refer to any instance variables of the class.
javac and java command are case sensitive.
null may be assigned to any variable, except the variables of primitive types.
In Java, an instance field declared as public generates a compilation error.
The default constructor automatically initializes the entire local variable to zero
If an exception is thrown, the finally block will be executed, even if no catch
statement matches the exception.
For switch statement the expression must be a type of short, byte, long, int and
char.
Java converts data into its String representation during concatenation by calling
one of the overloaded versions of valueOf defined in String class.
super keyword is more applicable to a situation in which member names of a
subclass hides member by the same name in the superclass.
The entry point of every application in Java is its main() method.
A class can implement many interfaces but can have only one superclass.
The InputStream class is an abstract class that lays the foundation the Java Input
class hierarchy.
Private members of superclass can be accessed by subclass’s member
functions/objects.
Only an import statement must appear as the first line in a source code file.
The readLine() method returns null when it has reached the end of a file.
A for statement can loop infinitely.
StringBuffer objects are constants.
A class that is declared without any access modifiers is said to have public access.
An interface is a non-functional class that can contain constants and method
declarations only.
An abstract class may be declared as final.
A string object once created cannot be modified.
To ensure controlled access to a shared resource by multiple threads, use
serialization.
All the methods in an abstract class must be declared abstract.
In dynamic method dispatch, the call to overridden methods is resolved at
runtime.
The objects System.out and System.in must be created explicitly by programmers.
Find the errors and correct. Justify your answer.
class Circle{
int radius;
static float Pi;
private Circle(){
Pi = 3.14;
i = radius;
}
void area(){
float ar = Pi * radius * radius;
return ar;
}
public static void main(String[] args){
Circle c = new Circle(3);
System.out.println(“Area of the circle : ”+area());
}
}
What is the problem with the following code snippet? Explain.
try{
int j = 0;
int j = 4;
int k = new int[4];
i = i /j;
}catch(Exception e){
}
catch(ArithmeticException e){
}catch(ArrayIndexOutOfBoundsException e){
*****