WorksheetsAccenture_Java_OOPs
Total questions: 50
Worksheet time: 3hrs 36mins
peep
bark
meow
Compilation fails
An exception is thrown at runtime.
Cat is-a Animal
Cat is-a Jumper
Dog is-a Animal
Beagle has-a Tail
Beagle has-a Jumper
Compilation fails.
An exception is thrown at runtime.
The attribute id in the Item object remains unchanged.
The attribute id in the Item object is modified to the new value.
A new Item object is created with the preferred value in the id attribute.
Which Man class properly represents the relationship "Man has a best friend who is a Dog"?
class Man extends Dog { }
class Man implements Dog { }
class Man { private BestFriend dog; }
class Man { private Dog bestFriend; }
class Man { private Dog<bestFriend>; }
What will be the result of attempting to compile and run the following code?
A) null
B) John
C) Compilation error
D) Runtime error
What does the following code demonstrate?
A) Inheritance
B) Polymorphism
C) Encapsulation
D) Abstraction
What will be the output of the following Java code?
0 0
5 6
6 5
5 5
What is the output of the following Java code?
5
0
Garbage Value
-1
What is the output of the following Java code?
8
10
0
Compilation Error
What will be the output of the following Java code?
1 2
2 1
Runtime Error
Compilation Error
What will be the output of the following Java program?
0
1
2
Compilation Error
What will be the output of the following Java program?
0
2
4
None of the mentioned
1,3 and 4
1,2 and 4
2,3 and 4
1,2,3 and 4
1 and 2 only
2,3 and 5
3,4 and 5
2 and 4
Which of these can be used to fully abstract a class from its implementation?
Objects
Packages
Interfaces
None of the Mentioned
What type of variable can be defined in an interface?
public static
private final
public final
static final
What does an interface contain?
Method definition
Method declaration
Method declaration and definition
Method name
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
The following Syntax is used for?
class Subclass-name extends Superclass-name
{
//methods and fields
}
Polymorphism
Encapsulation
Inheritance
None of the above
A class that is inherited is called a ______ .
superclass
Subclass
subsetclass
Relativeclass
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
What is an abstract method?
An abstract method is any method in an abstract class.
An abstract method is a method which cannot be inherited.
An abstract method is one without a body that is declared with the reserved word abstract.
n abstract method is a method in the child class that overrids a parent method.
A class can implement more than one interface?
True
False
A class can extend an interface?
True
False
An interface can extend an interface?
True
False
All members of an interface are public by default?
True
False
Predict the output:
20
10
Error in Object creation
None of the above
super keyword in Java is used for ?
to refer to immediate child class of a class.
to refer to current class object.
to refer to immediate parent class of a class.
to refer to static member of parent class.
Which is true ?
"X extends Y" is correct if X and Y are either both classes or both interface.
"X extends Y" is correct if and only if X is a interface and Y is a class.
"X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.
"X extends Y" is correct if and only if X is a class and Y is an interface.
If a class inheriting an abstract class does not define all of its function then it will be known as?
abstract
A simple class
Static class
None of the mentioned
Can an abstract class define both abstract methods and non-abstract methods?
No—it must have all one or the other.
No—it must have all abstract methods.
Yes—but the child classes do not inherit the abstract methods.
Yes—the child classes inherit both.
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 inheritance in java programming is not supported
Multiple inheritance using classes
Multiple inheritance using interfaces
Multilevel inheritance
Single inheritance
What is subclass in java?
A subclass is a class that extends another class
A subclass is a class declared inside a class
Both above.
None of the above.
Output of following Java program?
Base
Derived
Derived
Base
Base
Derived
Base
Derived
Base
Compiler Error
Predict the output of following program
Base
Derived
Compiler Error
Runtime Error
In Java, if a subclass defines a static method with the same signature as a static method in the superclass, what is this an example of?
Method overriding
Method overloading
Method hiding
Illegal code
Which of the following is/are false about inheritance in Java?
I. A subclass inherits all the methods and variables of the superclass.
II. A subclass can override the methods of its superclass
III. A subclass has access to the private instance variables of the superclass.
I only
II only
III only
I and II only
I and III only
Q14. What will the following program output?
(a)
Q1. (Multiple Choice)
Which type of polymorphism is achieved through method overloading?
Runtime polymorphism
Compile-time polymorphism
Dynamic polymorphism
None of the above
Q4. (Code Analysis)
What is the output of this code?
(a)
As a Vehicle user, we know how to use it but its internal working are not known. In OOPs Concept, this principle is known as
Encapsulation
Inheritance
Abstraction
Polymorphism
