0% found this document useful (0 votes)
16 views

BTech Semester III OOPJ Question Bank

The document is a comprehensive question bank for BTech Semester III OOPJ, designed to aid students in preparing for their university examinations. It covers various units including Basics of Java, Classes, Objects and Methods, Inheritance and Interfaces, JavaFX UI controls, Exception Handling, Multithreading, IO, and Class Modeling, with a mix of theoretical questions and programming tasks. Additionally, it includes multiple-choice questions to test understanding of key concepts.

Uploaded by

Shobhit Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

BTech Semester III OOPJ Question Bank

The document is a comprehensive question bank for BTech Semester III OOPJ, designed to aid students in preparing for their university examinations. It covers various units including Basics of Java, Classes, Objects and Methods, Inheritance and Interfaces, JavaFX UI controls, Exception Handling, Multithreading, IO, and Class Modeling, with a mix of theoretical questions and programming tasks. Additionally, it includes multiple-choice questions to test understanding of key concepts.

Uploaded by

Shobhit Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

BTech Semester III OOPJ Question Bank

The document is for reference questions for preparation of upcoming University


Examination.
Kindly solve the CET 1 and CET 2 and Remedial Paper of OOPJ for better
preparation.

Unit 1 – Basics of Java


Explain the role of JVM.
Define the following:
a. Bytecode
b. JVM
c. Unicode
The method main is a static method. Why?
How to interpret the following statement?
String [] s;
Compare String and StringBuffer.
Explain the short circuited operator with example.
What are wrapper classes? What are they usage?
What are the four integer types supported by Java? Explain with example.
What are command line arguments? Write a Java program that reads a line from command line
and prints that line in reverse.
Explain the features of Java.
State the difference between with examples with respect to String handling in Java.
a. append() versus insert()
b. length() versus capacity()
Explain the different types of control statements in Java.
Why is Java known as a platform-independent language?
Differentiate between simple and short-circuit logical operators, giving example.
What is data abstraction and encapsulation?
What are the data types used in Java? Give examples.
What is an array? How arrays are declared in Java? Explain with example.
List the primitive types in Java and explain with example.
PROGRAMS
Write a Java program to find whether the given string is palindrome or not.
Write a complete program to read from console up to n lines or until “quit” is entered. The lines
entered are displayed on the screen after reading all lines. The program also counts lines
beginning with character ‘A’ or ‘E’ as first letter.
Write Java program to print factorial of a number.
Write a Java program to sort an array of Strings entered through the keyboard.
Unit 2- Classes, Objects and Methods
Discuss public, private and protected access modifiers
What is constructor? Explain constructor overloading with example.
Discuss the following with example:
a. super
b. final
What is the use of “import” statement? Explain with example.
Explain dynamic method dispatch with example.
Explain the “this” keyword with example.
Differentiate constructor and method of a class.
Explain different visibility modifiers with example.
Explain the following terms with example:
a. Nested class b. Anonymous class
Explain the “finalize” keyword and the “static” keyword with example.
What constitutes the signature of a method?
How is garbage collection done in Java? Write the purpose of the finalize() method?
What is compile-time polymorphism? Use the compile time polymorphism in a Java program
to create the objects.
What is CLASSPATH? Explain with example.
What is a constructor? How is it different from other methods? Give an example where one
constructor is called from another in a class having multiple constructors. Can a class inherit
the constructor of its superclass? Why?
How is Garbage Collection done in Java? What is the significance of finalize() method?
What is the significance of modifier “final” for a class, method and a variable?
Explain about parameter passing technique with example.
What is a package? Explain how to create package with an example.
Explain in detail the process of defining, creating, importing and accessing a package with
example.
PROGRAMS
Declare a class called Book having book title & author name as
members. Create a sub-class of it, called BookDetails having
price & current stock of book as members. Create an array for
storing details of n books. Define methods to achieve following:
- Initialization of members
- To query availability of a book by author name / book title
- To update stock of a book on purchase and sell
Define method main to show usage of above methods.

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

Differentiate between method overloading and method overriding.


Explain interface and its usage with the help of an example
List two characteristics of an abstract class.
Explain the “instanceof” operator.
Explain interface in Java. How do interfaces support polymorphism?
Describe inheritance and its types with suitable example.
How would you define a group of constant that will be used by many classes?
Differentiate between class and interface.
What is an abstract class? How is it different from an interface? Explain why we cannot
instantiate any of these two.
Differentiate between runtime and compile-time polymorphism.
PROGRAMS
Write a Java program to demonstrate method overriding.
Write a Java program to explain runtime polymorphism using interfaces.
The abstract vegetable class has three subclasses named Potato, Brinjal and Tomato. Write a
java prog. That demonstrates how to establish this class
hierarchy. Declare one instance variable of type String that indicates the color
of a vegetable. Crete and display instances of these objects. Override the
toString() method of object to return a string with the name of vegetable and its
color.

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 4- JavaFX UI controls and multimedia

Explain the JavaFX UI Control


a. Label
b. Button
c. Checkbox
d. Radio Button
e. Text Field
f. Text area
g. Combo box
h. List View
i. Scrollbar
j. Video
k. Audio

Unit 4 – Exception Handling

Discuss exception and error.


Explain the importance of exception handling in Java. Which keywords are used to handle
exceptions? Explain with example.
Explain the use of “finally” in exception handling.
Differentiate between checked and unchecked exceptions.
When do we use “throws” statement? Explain with an example.
When do we use “throw” statement? Explain with an example.
State the difference between “final” and “finally”.
What is an exception? Explain different types of exceptions in Java.
What is the purpose of “finally” clause in a try-catch-finally statement?
PROGRAMS
Write a complete program to accept N integer numbers from the
command line. Raise and handle exceptions for following cases :
- when a number is –ve
- when a number is evenly divisible by 10
- when a number is greater than 1000 and less than 2000
- when a number is greater than 7000
Skip the number if an exception is raised for it, otherwise add it
to find total sum.
Define an exception class called “Mismatch Exception” that is thrown when two strings are not
equal. Write a program that uses this exception.

Unit 5 – Multithreading,

Draw and explain Thread Lifecycle


List and explain methods for inter-thread communication.
Explain Thread Life cycle and describe creation of thread with suitable example.
Explain the “synchronized” keyword.
What is a thread? What Java interface must be implemented by all threads? What is the
significance of run() method?
PROGRAMS
Write a multithreaded program to compute and print prime numbers up to n where n is given as
command line argument. Instantiate required number of threads where each thread except the
last, examines next 50 numbers and the last thread examines remaining numbers to check
whether a number is a prime or not.

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.

Write a method for computing Xy doing repetitive multiplication. X and y are of


type integer and are to be given as command line arguments. Raise and handle
exception(s) for invalid values of X and y.
Write a Java program to create two threads, one thread will check whether given number is
prime or not and the second thread will print the prime numbers between to 100.
Write Java program to create four threads using Runnable interface.

Unit 5 - IO

Explain the usage of FileInputStream and FileOutputStream with example.


Differentiate between Text I/O and Binary I/O.
What are streams? Explain their types.
What is the importance of InputStreamReader and OutputStreamWriter class in Java?
PROGRAMS
Create a class Student. Write a student manager program to manipulate the student information
from files by using BufferedReader and BufferedWriter class.
Write a program to check whether the name given from command line is file or not?
If it is a file then print the size of a file and if it is a directory then it should
display the name of all files in it.
Write a program using BufferedInputStream, FileInputStream, BufferedOutputStream,
FileOutputStream to copy content of one file Test1.txt into another file Test2.txt.
Write a Java program to count the number of characters in a file.

Unit 6 – Class Modeling

Define the terms:


Aggregation, Abstract class, Generalization, Constraints, Package, Metadata.
Discuss link and association in UML class diagram.
Explain aggregation and association.
MCQs
Solve the following
Choose the most appropriate answer from the choices
When overloading does not occur?
a. More than one method with same name but different method signature and different
number or type of parameters
b. More than one method with same name, same signature but different number of
signature.
c. More than one method with same name, same signature,same number of parameters,
but different type
d. More than one method with same name, same number of parameters and type but
different signature
Multiple inheritance means:
a. One class inheriting from more than one super classes
b. More classes inheriting from one super class
c. More classes inheriting from more super classes.
d. None of the above.
Analyze the following code:
public class Test {
public static void main(String[] args) {
int[] x = new int[5];
int i;
for (i = 0; i < x.length; i++)
x[i] = i;
System.out.println(x[i]);
}
}
a. The program displays 0 1 2 3 4
b. The program displays 4
c. The program has runtime error
d. None of the above
A top-level class may have which one of the following access modifiers:
a. Package
b. private
c. public
d. protected
void printOut(int I){
if (I== 0) return;
for (int i = I ; i > 0; i--){
System.out.println(“Line : ”+i)
}
printOut(i - 1)
}
What value should be passed to the method printOut(), so that ten lines will be printed?
a. 2
b. 3
c. 4
d. 5
If not assigned a value, a variable of type char has which default value?
a. ‘\u0001’
b. \uffff’
c. “ “ (space)
d. ‘\u0000’
When is an object eligible for garbage collection?
a. When an object becomes unreachable by any code
b. When the finalize method is called on the object’
c. When an object goes out of scope
d. When the system runs out of virtual memory
What would be the output of the following code?
public class Thread373 implements Runnable{
boolean flag = false;
public void start(){
if(!flag)
System.out.println(“Hello World”);
}
public static void main(String[] args){
Thread373 t = new Thread373();
t.start()
}
}
a. Compilation succeeds, Hello World is printed
b. Compilation succeeds, nothing is printed
c. Compilation fails
d. Execute with warnings
The hierarchy of exception classes commence from Throwable class which is the base class
in
a. java.lang
b. java.io
c. java.util
d. java.net
If your method overrides one of its superclass’s methods you can invoke the overridden
method through the use of the keyword
a. this
b. super
c. static
d. final
If q1 and q2 are objects of a Test class, then q1.equals(q2)
a. is true if q1 and q2 are references to the same test object
b. is a syntax error since equals is not defined in Test class
c. is true if q1 and q2 both store the same values
d. is never true
What is garbage collection in the context of Java?
a. When all references to an object are gone, the memory used by the object is
automatically reclaimed
b. The operating system periodically deleted all of Java files available on the system
c. Any package imported in a program and not used is automatically deleted.
d. The JVM checks the output of any Java program and deletes anything that doesn’t
make sense.
Which of the following is a correct interface declaration?
a. interface A { void print() ; }
b. interface A{ void print() {} }
c. abstract interface A { print(); }
d. abstract interface A { abstract void print() {} }
What exception type does the following program throw?
public class Test{
public static void main(String[] args){
Object o = null;
System.out.println(o);
}
}
a. ArithmeticException
b. NullReferencesException
c. StringIndexOutOfBoundsException
d. No Exception
The term “class variable” is another name for:
a. Local variable
b. static variable
c. instance variable
d. None of the above
Dynamic method dispatch is important because this is how Java implements:
a. Compile-time polymorphism
b. Encapsulation
c. Runtime polymorphism
d. Abstraction
All classes in Java are subclasses of which class:
a. Throwable
b. Object
c. String
d. Number
If you want to allow an element to be seen outside your current package, but only to subclass,
then declare that element as:
a. public
b. protected
c. private
d. static
The new operator :
a. returns a pointer to a variable
b. creates a variable called new
c. obtains a memory for a new variable
d. tells how much memory is available
What would happen when the following is compiled and executed?
public class Compare{
public static void main(String[] args){
int x = 10, y;
if (x < 10) y = 1;
if(x >= 10) y = 2;
System.out.println(“y is : ”+y);
}
}
a. The program does not compile and complains about y not being initialized
b. The program compiles and prints y is 0 when executed
c. The program compiles and prints y is 1 when executed
d. The program compiles and prints y is 2 when executed
All objects have toString() method which is inherited from:
a. Exception
b. Scanner
c. Object
d. String
Visualizing program components as objects is characteristics of which of the following
language types?
a. Object-Oriented Programming language
b. Machine language
c. Command line operating system
d. Procedural Language
What will be the result of the following code?
public class MyClass{
final int I;
public static void main(String[] args){
System.out.println(new MyClass().i);
}
}
a. Will print 0
b. Will give compiler error
c. Will give runtime error
d. Will give syntax error
Which are valid declarations for an integer literal?
i. 0
ii. 5
iii. 0416
iv. 0xabcdef
a. i and ii
b. i, ii, iii
c. iv
d. All of the above
Examine the following code:
public class LocalTest{
public static void main(String[] args){
int i;
System.out.println(“int i ”+i);
i = 20;
}
}
If you try to compile and run this class, what will happen?
a. It will compile, but will produce an interpreter error when executed
b. It will compile and output ‘0’ to the screen
c. It will compile and will give a compile error
d. None of the above
Which looping construct are you guaranteed to enter?
a. while
b. do-while
c. for
d. None of the above
Which is the base class for all Exception?
a. String
b. Error
c. Throwable
d. RuntimeException
What will be the output of the code fragment?
StringBuffer b = new StringBuffer(“abcdefg”);
b.delete(3,6);
b.append(“hij”);
System.out.println(b.toString());
a. abcdefghij
b. abcghij
c. abfghij
d. abchij
Which class is used for character stream in java.io?
a. FileOutputStream
b. ByteArrayOutputStream
c. FileWriter
d. PrintStream
Which of the following must match exactly for overloaded methods to compile correctly?
a. The parameter list
b. The return type
c. The method name
d. None of the above
The default value of String type is:
a. “ “(space)
b. null
c. none
d. 0
A program’s main() method takes an argument of:
a. String [] type
b. string [] type
c. Strings[] type
d. STRING[] type
Which of the following assignments is illegal in Java?
a. subclass_reference = subclass_object
b. subclass_reference = superclass_object
c. superclass_reference = subclass_object
d. superclass_reference = superclass_object
What will be the output, if any, of the following code segment?
class Min{
public static void main(String[] args){
int min = 30;
min(min, 20,10);
System.out.println(“Minimum of 10,20,30 is ”+min);
}
static void min(int min, int a, int b){
if(a > b) min = b;
else min = a;
}
}
a. 10
b. 20
c. 30
d. Program will not compile
Which one of the following is not a wrapper class?
a. Vector
b. Boolean
c. Character
d. Float
Which of the following is a Java keyword?
a. external
b. implement
c. throw
d. Integer
What is a bytecode in the context of Java?
a. The type of code generated by a Java compiler
b. The type of code generated by Java Virtual Machine
c. It is another name for Java source file
d. It is the code written within the instance methods of a class
What is the default priority of a newly created thread?
a. MIN_PRIORITY
b. NORM_PRIORITY
c. MAX_PRIORITY
d. A thread inherits the priority of its parent thread.
Which of the following method is used to initialize the instance variable of a class.
a. Class
b. Public
c. Constructor
d. Destructor
Method use to compare two strings is:
a. toString()
b. equals()
c. compare()
d. compareString()

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){

*****

You might also like