WorksheetsJAVA OOPS Test
Total questions: 88
Worksheet time: 3hrs 56mins
Default value of static integer variable of a class in java is
(a)
What is the default value of Boolean variable?
TRUE
FALSE
NULL
NOT DEFINED
Which of the following statements are true for inheritance in java?
"extend" keyword is used to extend a class in java.
You can extend multiple classes in java.
Private members of superclass are accessible to subclass.
We can’t extend Final classes in java.
Which of the following is not OOPS concept in Java?
Inheritance
Encapsulation
Polymorphism
Compilation
Which concept of Java is achieved by combining methods and attribute into a class?
Encapsulation
Inheritance
Polymorphism
Abstraction
Attributes of an object are also known as
methods
properties
classes
functions
Properties of an OOPS are also known __________________ of JAVA Programming
methods
Characteristics
classes
functions
Which of the following concepts of OOPs means exposing only necessary information and hiding the background details?
Encapsulation
Abstraction
Data hiding
Data binding
As blueprint is a design for a house, a class is a design for a(n):
object
variable
constant
statement
Which one is NOT the principle of OOP?
Class
Abstraction
BlueJ
Abstraction
Encapsulation
In OOP the main importance is given to the
methods
procdures
data
objects
Java uses both compiler and interpreter
true
false
The system of using the existing class in another class is called
encapsulation
abstraction
Inheritance
abstraction
Java was developed by
James gosling
John gosling
James frank
John frank
Consider the given code. What would be the display on the screen?
Class A
Class B
Class C
Compile error
What is the default value of a primitive int data type?
-1
null
0
garbage data
Encapsulation is a process of wrapping of data and methods in a single unit called ------------------------------
Variable
Functions
Class
Box
Which feature of OOPS derives the class from another class?
Inheritance
Data hiding
Encapsulation
Polymorphism
How many types of polymorphism in the C++ programming language?
Three types of polymorphism
Two types of polymorphism
Five types of polymorphism
Four types of polymorphism
Which of the following OOP concept binds the code and data together and keeps them secure from the outside world?
Polymorphism
Inheritance
Abstraction
Encapsulation
Which member of the superclass is never accessible to the subclass?
Public member
Protected member
Private member
All of the mentioned
How can the concept of encapsulation be achieved in the program?
By using the Access specifiers
By using the concept of Abstraction
By using only private members
By using the concept of Inheritance
Which definition best defines the concept of abstraction?
Hides the important data
Hides the implementation and showing only the features
Hiding the implementation
Showing the important data
Which of the following definition best describes the concept of polymorphism?
It is the ability to process the many messages and data in one way
It is the ability to process the undefined messages or data in at least one way
It is the ability to process the message or data in more than one form
It is the ability to process the message or data in only one form
Which one of the following is not true?
A class containing abstract methods is called an abstract class.
Abstract methods should be implemented in the derived class.
An abstract class cannot have non-abstract methods.
A class must be qualified as ‘abstract’ class, if it contains one abstract method.
What will be the output of the given program?
Base::show() called
Derived::show() called
Compiler Error
Runtime Error
What will be the output of the given program?
Base::show() called
Derived::show() called
Compiler Error
Which of the following is true about inheritance in Java?
1) Private methods are final.
2) Protected members are accessible within a package and
inherited classes outside the package.
3) Protected methods are final.
4) We cannot override private methods.
1, 2 and 4
Only 1 and 2
1, 2 and 3
2, 3 and 4
Predict the output of the following Java program
class Test {
int i;
}
class Main {
public static void main(String args[]) {
Test t = new Test();
System.out.println(t.i);
}
}
garbage value
0
compiler error
runtime error
The output of the following Java program?
Compilation error
Inside First
Inside Second
Inside First
Inside First
Runtime error
What is the output of the following JAVA program?
dogood : dogoodgood
dogood : gooddogood
dogood : dogood
dogood : gooddogood
In Java, when we implement an interface method, it must be declared as:
Private
Protected
Public
Friend
In Java, when we implement an interface method, it must be declared as:
Private
Protected
Public
Friend
A ___________ is a pre-defined set of steps that complete a specific task, optionally based on parameter values, and optionally returning some result.
array
function
method
module
class
what is the output of this question?
class Test1 {
public
static void main(String[] args)
{
int x = 20;
System.out.println(x);
}
static
{
int x = 10;
System.out.print(x + " ");
}
}
10 20
20 10
10 10
20 20
Predict the output of the following program.
class A{
int a=40;//non static
public static void main(String args[]){
System.out.println(a);
}
}
Compilation Error
40
0
None of the above
what is the output of this question?
class Test1 {
static int x = 10;
public
static void main(String[] args)
{
Test1 t1 = new Test1();
Test1 t2 = new Test1();
t1.x = 20;
System.out.print(t1.x + " ");
System.out.println(t2.x);
}
}
10 10
20 20
10 20
20 10
What is the output of this question?
class Test1 {
static int i = 1;
public static void main(String[] args)
{
for (int i = 1; i < 10; i++) {
i = i + 2;
System.out.print(i + " ");
}
}
}
3 6 9
3 6 9 …. 27
Error
none
What is the output of this question?
class Test1 {
static int i = 1;
public static void main(String[] args)
{
int i = 1;
for (Test1.i = 1; Test1.i < 10; Test1.i++) {
i = i + 2;
System.out.print(i + " ");
}
}
}
1 3 9
1 2 3 … 9
3 5 7 9 11 13 15 17 19
None
What will be the output?
public class Test
{
public static void main(String args[])
{
int[] x=new int[3];
System.out.print("x[0] is" + x[0]);
}}
The program has a compile error because the size of the array wasn't specified when declaring the array.
The program has a runtime error because the array elements are not initialized.
The program runs fine and displays x[0] is 0.
The program has a runtime error because the array element x[0] is not defined
An Array in Java is a collection of elements of ___ data type.
Same
Different
The keyword "static" in Java is used with
Method
Block
Variable
All the Above
Which of the following variable is declared as static?
Home address of a particular Student
Account number of a Customer
Company name of all Employees in an Organization
Name of a Employee
What is the output of the following code?
public class Demo
{
public void show(int a)
{
System.out.println(a);
}
public static void main(String[] args)
{
show(20);
}
}
20
No Output Displayed
a constant is passed as argument
Compile Time Error
Which of the following is not a correct statement?
A class can have any number of static blocks
Static method is accessed directly using class name
Separate memory is allocated for each object for all static variables
Static method is executed before main() method once a class is loaded
Static variables belongs to an Object?
Yes
No
What is the output of the following code?
public class Demo
{
static int x=10;
int y =15;
public Demo()
{
x++;
y++;
}
public static void main(String[] args)
{
Demo d1= new Demo();
Demo d2= new Demo();
Demo d3= new Demo();
System.out.println(d3.x + " , " +d3.y);
}
}
13,15
13,16
13,18
10, 18
Which of the following is Mutable object
String
StringBuffer
Which of these class is super class of every class in Java?
String class
Object class
ArrayList class
Abstract class
Which of these keywords can be used to prevent inheritance of a class?
super
constant
extends
final
Which of these class relies upon its subclasses for complete implementation of its methods?
Object class
abstract class
ArrayList class
None of the mentioned
What will be the output of the following Java program?
2
0
Compilation Error
Runtime Error
Which of these keywords are used to define an abstract class?
Abstract
abstract
abstract class
abst
In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?
Protected
Private
Public
Static
If super class and subclass have same variable name, which keyword should be used to use super class?
this
super
upperclass
classname
What is the use of final keyword in Java?
When a class is made final, a sublcass of it can not be created.
When a method is final, it can not be overridden.
When a variable is final, it can be assigned value only once.
All of the above
float myFloatNum = 5.99f;
System.out.println(myFloatNum);
What will be the output?
5.99
5.99f
"5.99"
"5.99"f
Name the data type: 1.0
double
int
char
boolean
Which of the following is the right way of defining char variable?
char myGrade = 'B';
char myGrade = "B";
char myGrade 'B';
char myGrade = "B"
int sum1 = 100 + 50;
int sum2 = sum1 + 250;
int sum3 = sum2 + sum2;
System.out.println(sum3);
What will be the final output?
950
800
sum2sum2
sum1250
int x = 10;
x = x + 5;
System.out.println(x);
What will be the output?
15
5
55
x5
int x = 4;
System.out.println(x < 5 && x < 10);
What will be the output?
false
true
4
x < 5 && x < 10
int x = 4.4;
int y = 5.5;
System.out.println(x == y);
What will be the output?
4.4
true
false
5.5
What is the output of below code?
int x = 5;
System.out.println(x++);
System.out.println(x);
5
5
6
6
5
6
6
5
Concatenation(+)operator is used for joining two strings
true
false
Which of the following is not an OOPS concept in java ?
Polymorphism
Inheritance
Compilation
Encapsulation
Which of these are selection statements in java
Break
Continue
For ( )
If ( )
Which of these keywords is used to define interfaces in java
intf
Intf
interface
Interface
Which one of the following is not an access modifier ?
Protected
Void
Public
Private
When does method overloading is determined?
At run time
At compile time
At coding time
At execution time
When overloading does not occur ?
More than one method with same name but different method signature and different number or type of parameters
More than one method with same name,same signature but different number of signature
More than one method with same name,same signature,same number of parameters but different type
More than one method with same , same number of parameters and type but different signature
Method overriding is combination of inheritance and polymorphism ?
True
False
Which of the below is invalid identifier with the main method
Public
Static
Private
Final
What will be the output of the following Java program?
0
2
4
None of these
Which of these can be used to fully abstract a class from its implementation?
Objects
Packages
Interfaces
None of the Mentioned
What is the output of this program?
a=10
a=20
Compilation Error
No Error, but no output
What type of variable can be defined in an interface?
public static
private final
public final
static final
Which of the following is correct way of implementing an interface salary by class manager?
class manager extends salary {}
class manager implements salary {}
class manager imports salary {}
None of the mentioned.
Abstract class can have constructors and static methods?
TRUE
FALSE
Abstract class can have constructors but can not have static methods.
Abstract class can not have constructors but can have static methods.
Which of these is not a correct statement?
Every class containing abstract method must be declared abstract
Abstract class defines only the structure of the class not its implementation
Abstract class can be initiated by new operator
Abstract class can be inherited
A class that is inherited is called a ______ .
superclass
Subclass
subsetclass
Relativeclass
Class dog implements the animal interface.
Which IS a valid declaration?
Dog d = new Animal();
Animal d = new Dog();
Animal d = new Animal();
When overloading a method, the method header ________ .
Must exactly match the header of the method you are overloading.
Must have the same name, but differ in order, number, or type of parameters.
Can differ in name, but must have the same number and order of parameters.
Can be completely different from the method you are overloading, but must have @Override.
Which of the following statements is invalid?
Tutor jimmy = new CSTutor();
CSTutor sally = new JavaTutor();
Tutor suzie = new JavaTutor();
Tutor johnny = new Tutor();
Abstract class can have
Abstract methods
Methods with code implementation
Used to create objects
Used to create subclasses
