0% found this document useful (0 votes)
2 views25 pages

Questionnaire MS Java

The document contains a questionnaire with multiple-choice questions related to Java programming concepts, including collections, lambda expressions, method overriding, HTTP methods, and the Stream API. Each question is followed by the correct answer and an explanation of the concepts involved. The content is structured to test knowledge of Java features and best practices.

Uploaded by

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

Questionnaire MS Java

The document contains a questionnaire with multiple-choice questions related to Java programming concepts, including collections, lambda expressions, method overriding, HTTP methods, and the Stream API. Each question is followed by the correct answer and an explanation of the concepts involved. The content is structured to test knowledge of Java features and best practices.

Uploaded by

Saurabh Gupte
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Questionnaire:

1. Collection ______________
a. inherits the Collections class
b. inherits the Iterable interface
c. implements the Serializable interface
d. implements the Traversable interface
Answer: b (Explanation: Collection is an interface and inherits from the Iterable interface. Also
Collection is both a framework and interface)

2. Which of the following interfaces maintains the order in which the elements are inserted?
a. Set
b. List
c. Map
d. All the answers are true

Answer: b (Explanation: List maintains the insertion order. In Set, only the LinkedHashSet
implementation maintains the insertion order. In Map, LinkedHashMap maintains the insertion
order)

3. Which one is best suited for a multi-threaded environment?


a. WeakHashMap
b. Hashtable
c. HashMap
d. ConcurrentHashMap

Answer: d (The ConcurrentHashMap class of the Collections framework provides a thread-safe


Map. In other words, several threads can access the map at the same time without affecting the
consistency of the entries in a map.)
4. What is the difference between Collection and Collections in Java?
a. Collection is the interface where you group objects into a single unit. Collections is a
utility class that has some set of operations you perform on Collection
b. Collections is the interface where you group objects into a single unit. Collection is a
utility class that has some set of operations you perform on Collection

Answer: a

[Link] Collection in Java Collections in Java

1 In Java, collection is an interface. In Java, collections is a utility class.

2 It showcases a set of individual It represents multiple utility processes


objects as a single unit. and methods like sorting and searching
that are utilized to operate on collection.
These techniques allow the developers to
actually work with the collection
framework.

3 This interface includes a static It only includes static methods.


method since java8. It can also
have both default and methods.

5. Which of the following is true about hashtable?


a. Hashtable class contains unique elements.
b. Hashtable class doesn't allow null key or value.
c. Both A & B
d. Hashtable class is non-synchronized.
Answer: c (Explanation: HashMap is non-synchronized. It is not thread-safe and can’t be shared
between many threads without proper synchronization code whereas Hashtable is
synchronized. It is thread-safe and can be shared with many threads. HashMap is generally
preferred over HashTable if thread synchronization is not needed
HashMap allows one null key and multiple null values whereas Hashtable doesn’t allow any null
key or value and hence Hashtable contains unique elements)

6. If large number of items are stored in hash bucket, what happens to the internal structure?
a. The bucket will switch from LinkedList to BalancedTree
b. The bucket will increase its size by a factor of load size defined
c. The LinkedList will be replaced by another hashmap
d. Any further additions will throw Overflow exception

Answer: a (Explanation: BalancedTree will improve performance from O(n) to O(log n) by


reducing hash collisions)

7. If there is a situation where two or more key objects produce the same final hash value and
hence point to the same bucket location or array index, what is it called?
a. Diffusion
b. Replication
c. Collision
d. Duplication
Answer: c (Explanation: In a hash table, if several elements are computing for the same bucket
then there will be a clash among elements. This condition is called Collision. HashMap handles
collision by using a linked list to store map entries ended up in same array location or bucket
location. From Java 8 onwards, HashMap, ConcurrentHashMap, and LinkedHashMap will use the
balanced tree in place of linked list to handle frequently hash collisions)

8. What is the return type of lambda expression?


a. String
b. Object
c. Void
d. Function
Answer: d (Explanation: Lambda expression enables us to pass functionality as an argument to
another method, such as what action should be taken when someone clicks a button
Lambda expressions basically express instances of functional interfaces (An interface with single
abstract method is called functional interface. An example is [Link]). lambda
expressions implement the only abstract function and therefore implement functional interfaces
lambda expressions provide below functionalities.
Enable to treat functionality as a method argument, or code as data.
A function that can be created without belonging to any class.
A lambda expression can be passed around as if it was an object and executed on demand)

9. What is Optional object used for?


a. Optional is used for optional runtime argument
b. Optional is used for optional spring profile
c. Optional is used to represent null with absent value
d. Optional means it’s not mandatory for method to return object
Answer: c (Explanation: Optional object is used to represent null with absent value. This class
has various utility methods to facilitate code to handle values as ‘available’ or ‘not available’
instead of checking null values.)

10. What is the substitute of Rhino javascript engine in Java 8?


a. Nashorn
b. V8
c. Inscript
d. Narcissus
Answer: a (Explanation: Nashorn provides 2 to 10 times faster in terms of performance, as it
directly compiles the code in memory and passes the bytecode to JVM. Nashorn uses invoke
dynamic [Link] is used for optional runtime argument)

11. Lambdas introduced in Java 8 allow us to process_____


a. Data as code
b. Code as data
c. None of the above
d. All the answers are true
Answer: b (Explanation: Lambda expressions allow you to treat functionality as a method
argument = code as data. This means that the code of your program that you write is also data
that can be passed as an argument to another method and manipulated by a program
Syntax of Lambda Expression:
(argument-list) -> {body}
Lambda expressions basically express instances of functional interfaces (An interface with single
abstract method is called functional interface. An example is [Link]). lambda
expressions implement the only abstract function and therefore implement functional interfaces
lambda expressions provide below functionalities.
Enable to treat functionality as a method argument, or code as data.
A function that can be created without belonging to any class.
A lambda expression can be passed around as if it was an object and executed on demand)

12. What class can be used instead of [Link]() to get date and time in Java 8?
a. Clock
b. Timer
c. Time
d. Date
Answer: a

13. Lambda expressions in java 8 are based on _____


a. Procedural programming
b. Functional programming
c. Data programming
d. All the answers are true
Answer: b (Explanation: Lambda expressions are like a way to support functional programming
in Java. Functional programming is a paradigm for programming using expressions, declaring
functions, passing functions as arguments, and using functions as instructions (called
“expressions” in Java 8). Lambda expressions basically express instances of functional interfaces
(An interface with single abstract method is called functional interface. An example is
[Link]). lambda expressions implement the only abstract function and therefore
implement functional interfaces
lambda expressions provide below functionalities.
Enable to treat functionality as a method argument, or code as data.
A function that can be created without belonging to any class.
A lambda expression can be passed around as if it was an object and executed on demand)

14. Which of the following are functional interfaces? (Select ALL that apply)
a. [Link]
b. [Link]
c. [Link]
d. [Link]
e. [Link]
Answer: b, c, d, e (Explanation: The interface [Link] is not a functional
interface–it has numerous abstract methods. The other four options are functional interfaces.
The functional interface [Link] has an abstract method with the signature
void accept(T t).
The functional interface [Link] has an abstract method with the signature T
get().
The functional interface [Link] has an abstract method with the signature
boolean test(T t);
The functional interface [Link] has an abstract method with the signature R
apply(T t).)

15. PermGen space has been replaced with which of these in Java 8
a. PermSpace
b. PermSpaceGen
c. Metaspace
d. MetaGenSpace

Answer: c (Explanation: PermGen always has a fixed maximum size & inefficient garbage
collection. MetaSpace grows automatically by default. Here, the garbage collection is
automatically triggered when the class metadata usage reaches its maximum metaspace size,
leading to efficient garbage collection)

16. Which of the following are intermediate operations?


a. Limit
b. Peek
c. anyMatch
d. skip

Answer: a, b and d (Explanation: limit, peek, and skip are intermediate operations. The
anyMatch is a terminal operation.)

17. Which of the following are terminal operations?


a. Sorted
b. flatMap
c. max
d. distinct

Answer: c (Explanation: max is the only terminal operation. sorted, flatMap, and distinct are
intermediate operations.)

18. What is the process of defining a method in a subclass having same name & type signature as a
method in its superclass?
a. Method overloading
b. Method overriding
c. Method hiding
d. None of the mentioned
Answer: b (Explanation: If a subclass provides the specific implementation of the method that
has been declared by one of its parent class, it is known as method overriding. Method
overriding is used to provide the specific implementation of a method which is already provided
by its superclass. Method overriding is used for runtime polymorphism- Java virtual machine
determines the proper method to call at the runtime, not at the compile time. It is also called
dynamic or late binding.)

19. Which of these keywords can be used to prevent Method overriding?


a. Static
b. Constant
c. Protected
d. final
Answer: d (Explanation: To disallow a method from being overridden, specify final as a modifier
at the start of its declaration. Methods declared as final cannot be overridden.)

20. What are the advantages of Method Overriding in Java?


a. A subclass can add extra functionality to the overriding method.
b. A subclass can call both the overridden method and overriding method.
c. It supports polymorphism. A superclass reference can be used to call the common
method of all subclasses.
d. All the above
Answer: d (Explanation: All of the above.)

21. What is the process of defining two or more methods within same class that have same name
but different parameters declaration?
a. Method overloading
b. Method overriding
c. Method hiding
d. none of the mentioned

Answer: a (Explanation: Two or more methods can have same name as long as their parameters
declaration is different, the methods are said to be overloaded and process is called method
overloading. Method overloading is a way by which Java implements polymorphism. Advantage
of method overloading is it increases the readability of the program.

There are 2 different ways to overload the method a) By changing number of arguments and b)
By changing the data type. Method overloading is used for compile time polymorphism- At
compile-time, java knows which method to call by checking the method signatures. So this is
called compile-time polymorphism or static or early binding)

22. Which of the following are HTTP methods?


a. GET
b. CREATE
c. POST
d. PUT
e. DELETE
f. PATCH
g. OPTIONS

Answer: a, c, d, e, f and g (Explanation:

GET: This is used for fetching details from the server and is basically a read-only operation.
POST: This method is used for the creation of new resources on the server.

PUT: This method is used to update the old/existing resource on the server or to replace the
resource.

DELETE: This method is used to delete the resource on the server.

PATCH: This is used for modifying the resource on the server.

OPTIONS: This fetches the list of supported options of resources present on the server.

The POST, GET, PUT, DELETE corresponds to the create, read, update, delete operations which
are most commonly called CRUD Operations. GET, HEAD, OPTIONS are safe and idempotent
methods whereas PUT and DELETE methods are only idempotent. POST and PATCH methods are
neither safe nor idempotent
([Link]
and-explain-its-relevancy-in-restful-web-services))

23. What is the difference between intermediate and terminal operations? (Select ALL that apply)
a. The intermediate operation produces stream pipelining, Terminal operation terminate
the pipeline
b. Intermediate operations can be chained multiple times on a stream, Terminal
operations cannot be chained various times.
c. Intermediate operations cannot be evaluated independently; it needs a terminal
operation for evaluation. Terminal Operations can be evaluated independently.
d. All the above
Answer: d (Explanation: All the above)

24. Method reference is used to refer method of functional interface (Select True or False)
a. True
b. False

Answer: a (Explanation: Method reference is used to refer method of functional interface. It is


compact and easy form of lambda expression. Each time when you are using lambda expression
to just referring a method, you can replace your lambda expression with method reference. In
this tutorial, we are explaining method reference concept in detail. Following are the types of
method references in java: a) Reference to a static method b) Reference to an instance method
c) Reference to a constructor.)

25. The Stream API is used to process a group of objects. A stream is a series of objects which
supports different methods that can be pipelined to produce the expected result.

Which of the below features of the stream are True–

a. A stream takes the input from the Collections, an Arrays or the I/O channels.
b. Streams don’t alter the original data structure; they only give the result according to the
pipelined methods.
c. Each intermediate operation is executed in a lazy manner, and as a result, it returns a
stream. Hence various intermediate processes can be pipelined. The terminal operations
remain at the end of the pipelining process. It replaces the final value, and the pipeline
is terminated.
d. All the Java stream API interfaces and classes are in [Link] package
e. Streams are not modifiable i.e one can’t add or remove elements from streams.
f. It stores/holds all the data that the data structure currently has in a particular data
structure like Set, List or Map,
g. They don’t use functional interfaces.

Answer: a, b, c, d and e (Explanation: f. is not true as Streams doesn’t store data, it operates
on the source data structure i.e.; collection. g. is not true as Streams use functional
interfaces like lambda which makes it a good fit for programming language.)

26. What is the difference between Comparable and Comparator? (Select ALL that apply)
a. Comparable provides a single sorting sequence. In other words, we can sort the
collection on the basis of a single element such as id, name, and price. The Comparator
provides multiple sorting sequences. In other words, we can sort the collection on the
basis of multiple elements such as id, name, and price etc.
b. Comparable affects the original class, i.e., the actual class is modified. Comparator
doesn't affect the original class, i.e., the actual class is not modified.
c. Comparable provides compareTo() method to sort elements. Comparator provides
compare() method to sort elements.
d. Comparable is present in [Link] package. A Comparator is present in the [Link]
package.
e. We can sort the list elements of Comparable type by [Link](List) method. We
can sort the list elements of Comparator type by [Link](List, Comparator)
method.
f. All the above

Answer: All the above

27. Which of the following statement is correct? (Choose two)


a. Spring is an open source framework.
b. Spring is heavyweight.
c. Spring supports tight coupling.
d. Spring using Dependency Injection and supports loose coupling.

Answer: a and d

28. What is the default scope of the beans?


a. Prototype
b. Session
c. Request
d. Singleton

Answer: d (Explanation: Singleton scope in the spring framework is the default bean scope in
the IOC container. It tells the container to exactly create a single instance of the object. This
single instance is stored in the cache and all the subsequent requests for that named bean
return the cached instance. The word “Singleton” in Spring is used for a bean scope, which
means that the bean will only be created once for the entire application. Singleton usually
stands for the GOF (Gang of Four) pattern. It is an object-oriented model ensuring that there will
only be one instance of a class.)

29. What is Bean in Spring?


a. Component
b. Object
c. Class
d. Container

Answer: b (Explanation: In Spring, the objects that form the backbone of your application and
that are managed by the Spring IoC container are called beans. A bean is an object that is
instantiated, assembled, and otherwise managed by a Spring IoC container)

30. How does spring achieve Dependency Injection or IOC (Inversion of Control)?
a. Service locator pattern
b. Factory pattern
c. Abstract factory pattern
d. Singleton pattern

Answer: a (Explanation: The service locator pattern has the same goal as dependency injection.
It removes the dependency that a client has on the concrete implementation. The following
quote from Martin Fowler’s article summaries the core idea:

“The basic idea behind a service locator is to have an object that knows how to get hold of all of
the services that an application might need. So, a service locator for this application would have
a method that returns a ‘service’ when one is needed.”)

31. Dependency injection or IOC is a _____________?


a. Design Pattern
b. Framework
c. Java Module
d. ORM Framework
Answer: a (Explanation: In software engineering, dependency injection is a technique by which
one object provides dependencies to another object. A dependency is a usable object (a
service). An injection is the passage of a dependency to a dependent object (a client) that would
use it.)

32. Which class does the IoC container represent?


a. ApplicationContext
b. ServletContext
c. RootContext
d. WebApplicationContext
Answer: a (Explanation: The IoC (Inversion of Control) container is responsible for instantiating,
configuring, and aggregating objects. The IoC container obtains information from the XML file
and operates accordingly. The main tasks performed by the IoC container are as follows:
Instantiate the application class
Configure the object
Aggregate dependencies between objects)

33. Beans can be created by which of the following properties?


a. Static factory-method
b. Instance Factory-Method
c. All of the above
d. None of the above

Answer: c (Explanation: All of the above)

34. Is Singleton beans are thread safe in Spring Framework?


a. No, singleton beans are not thread-safe in Spring framework.
b. Yes, singleton beans are thread-safe in Spring framework.

Answer: a (Explanation: No, singleton beans are not thread-safe in Spring framework.)

35. @Component annotation on class indicates


a. that a bean should be created for the class
b. that a bean should not be created for the class
c. that autowiring should be enabled for the class
d. that autowiring should not be enabled for the class
Answer: a (Explanation: @Component is an annotation that allows Spring to automatically
detect our custom beans. In other words, without having to write any explicit code, Spring will:
Scan our application for classes annotated with @Component. Instantiate them and inject any
specified dependencies into them. Inject them wherever needed)

36. What types of dependency injection does Spring support?


a. Based on the constructor and setters
b. Based on the constructor, setters, and getters
c. Based on setters, getters, and properties
d. Based on the constructor, setters, and properties
Answer: a (Explanation: Spring supports constructor-based and setters-based injections.)

37. Choose the correct code for merge sort?


a) void merge_sort(int arr [], int left , int right){
if (left > right) {
int mid = (right - left)/2;
merge_sort(arr, left, mid);
merge_sort(arr, mid+1, right);

merge(arr, left, mid, right); //function to merge sorted arrays


}
}
b) void merge_sort(int arr [], int left , int right){
if (left < right) {
int mid = left+(right - left)/2;
merge_sort(arr, left, mid);
merge_sort(arr, mid+1, right);

merge(arr, left, mid, right); //function to merge sorted arrays


}
}
c) void merge_sort(int arr [], int left , int right){
if (left < right) {
int mid = left + (right - left)/2;
merge(arr, left, mid, right); //function to merge sorted arrays
merge_sort(arr, left,mid);
merge_sort(arr, mid+1 , right);

}
}
d) void merge_sort(int arr [], int left , int right){
if (left < right) {
int mid = (right - left)/2;
merge(arr, left, mid, right); //function to merge sorted arrays
merge_sort(arr, left,mid);
merge_sort(arr, mid+1 , right);

}
}
Correct Answer: B
Explanation:Merge Sort is a Divide & Conquer principle based algorithm. It divides input array in
two halves, calls itself for the two halves and then it merges the two sorted halves to obtain
sorted array.

38. Using stream api, filter list of employees having experience greater than 2 from city Delhi.

a) List<Employee> empSortList = [Link]()


.filter(e -> "Delhi".equals([Link]()) && [Link]() > 2);
b) List<Employee> empSortList = [Link]()
.filter(e -> "Delhi".equals([Link]()) && [Link]() > 2)
.collect();
c) List<Employee> empSortList = [Link]()
.filter(e -> "Delhi".equalsIgnoreCase([Link]()) && [Link]() > 2)
.collect([Link]());
d) List<Employee> empSortList = [Link]()
.filter(e -> "Delhi".equalsIgnoreCase([Link]()) || [Link]() > 2)
.collect([Link]());
Correct Answer: C

39. Select correct method to sort list of numbers.


a)[Link]()
b) [Link]()
c) [Link]()
d) [Link]()
Correct Answer: A, B (keep multiple checklist)
Explanation: [Link]() works for arrays which can be of primitive data type also which in turn
by default sorts in ascending order.
The [Link]() method is also used to sort the linked list, array, queue, and other
data structures.
4] The LRU algorithm
a) pages out pages that have been used recently

b) pages out pages that have not been used recently

c) pages out pages that have been least used recently

d) pages out the first page in a given area

Correct Answer: C

40. Choose the code to merge two arrays and sort it.
a) public void merge(int[] nums1, int m, int[] nums2, int n) {
for (int i = 0; i < n; i++) {
nums1[i + m] = nums2[i];
}
[Link](nums1);
}
b) public void merge(int[] nums1, int m, int[] nums2, int n) {
for (int i = 0; i < n+1; i++) {
nums1[i + m] = nums2[i];
}
[Link](nums1);
}
c) public void merge(int[] nums1, int m, int[] nums2, int n) {
for (int i = 0; i < n+1; i++) {
nums1[] = nums2[i+n];
}
[Link](nums1);
}
d) public void merge(int[] nums1, int m, int[] nums2, int n) {
for (int i = 1; i < n; i++) {
nums1[i + m] = nums2[i];
}
[Link](nums2);
}
Correct Answer: A

41. Complexity for priority queue


a) O(n)
b) O(1)
c) O(n log(n))
d) O(log(n))
Correct Answer: D
Explanation: Complexity of PriorityQueue

PriorityQueue
log(n) operations: offer(), poll(), remove(), add()
O(1) opearations: peek(), size()
O(n) operations: remove(object), contains(object)

42. While using Mockito which annotation is used to create a real object and spy on that real object.
a) @Mock
b) @captor
c) @spy
d) @InjectMocks

Correct Answer: D
Explanation:
The @Spy annotation is used to create a real object and spy on that real object. A spy helps to
call all the normal methods of the object while still tracking every interaction, just as we would
with a mock.

43. If the class implements [Link], then it is serializable.


a) True
b) False

Correct Answer: A
Explanation: The class must implement the [Link] interface to achieve serialization.

44. Which layer in spring boot architecture, handles the HTTP requests, translates the JSON
parameter to object, and authenticates the request and transfer it further layer.
a) Presentation Layer
b)Business Layer
c)Persistence Layer
d)Database Layer
Correct Answer: A

Explanation:
Presentation Layer: The presentation layer handles the HTTP requests, translates the JSON
parameter to object, and authenticates the request and transfer it to the business layer. In
short, it consists of views i.e., frontend part.

45. Which of the following dependency is used to implement Aop in spring boot?
a) spring-boot-starter-aspect
b) spring-boot-starter-aop
c) spring-boot-starter-aspectj
d)None of the above
Correct Answer: B
Explanation:
To implement AOP, start with including the spring-boot-starter-aop module in the application
dependencies. It transitively imports spring-aop and aspectjweaver dependencies into the
application.

<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>

46. What is an advice? Select a unique answer?


a) An action taken by an aspect at a particular jointpoint
b) A point during the execution of program
c)An aspect and point cut
d) A predicate that matches join points
Correct Answer: A
Explanation:
In Spring AOP, a join point always represents a method execution. Advice: action taken by an
aspect at a particular join point. Different types of advice include "around," "before" and "after"
advice.

47. We get unchecked exceptions at?


a) Compile time
b) Runtime
c) Both (a) and (b)
d) None of these

Correct Answer: B
Explanation:
Unchecked exception caught at run time when we execute the java program. Unchecked java
exceptions example are ArithmeticException, null pointer exception etc. let’s say at the run time
in the program if a number divide by zero occurs then arithmetic exception happens.

48. ArrayList is better for _______ data. LinkedList is better for _______ data.
a) storing, accessing
b) storing and accessing, manipulating
c) manipulating, storing
d) storing, manipulating
Correct Answer: B
Explanation:
ArrayList is better for storing and accessing data. LinkedList is better for manipulating data.

49. The object of Criteria can be obtained by calling the ________ method of Session interface.

a) addCriteria()
b) setCriteria()
c) createCriteria()
d) getCriteria()

Correct Answer: C
Explanation:
The Criteria interface provides many methods to specify criteria. The object of Criteria can be
obtained by calling the createCriteria() method of Session interface.
Syntax:
Crietria c=[Link]([Link]);

50. By default, Spring Boot will instantiate its default DataSource with the configuration properties
prefixed by [Link].*:
a)True
b)False

Correct Answer: A
Explanation:
If multiple databases are configured in spring boot application then By default, Spring Boot will
instantiate its default DataSource with the configuration properties prefixed by
[Link].*:

51. What is the below output of the below java program with Method Overriding?
Class Bus
{
Void seatingCapacity ()
{
[Link](“Superclass Seat=32”);
}
}
Class ElectricBus extends Bus
{
Void seatingCapacity()
{
[Link](“Subclass Seats=20”);
}
Void showInfo()
{
seatingCapacity();
[Link]();
}
}
Public class MethodOverriding1
{
Public static void main (String[] args)
{
ElectricBus eb = new ElectricBus();
[Link]();
}
}

a)
Subclass seats =20
Superclass Seats =32
b)
Superclass Seats =32
Subclass Seats=20
c)
Superclass Seats=32
Superclass Seats=32
d)
Subclass Seats=20
Subclass Seats=20
Correct Answer: d
Explanation: Using the keyword “this” calls the local method of the class but nit the method of a
superclass.

52. Identify INVALID java Method Overriding in the below code snippets?
Follow the notation “superclass Method” and “subclass Method”.
a)
void superclassMethod(int a,float b) {}
void subclassMethod(int a,float b){}
b)
void superclassMethod(){}
void subclassMethod(){}
c)
int superclassMethod(int a, float b){}
void subclassMethod(int a,float b){}
d)
None.
Correct Answer: c
Explanation:
The return types are different. So it is not a successful method override.

53. What is the output of the below java program with method overriding?
Class Cat
{
int jumpingHeight( int weight )
{
[Link](10);
return 10;
}
}
Class WildCat extends Cat
{
Void jumpingHeight( int weight)
{
[Link](“20);
}
}
Public class MethodOverriding3
{
Public static void main( String [] args)
{
WildCat wc =new Wildcat();
[Link](30);
}
}
a)10
b)20
c)30
d)Compiler error
Correct Answer: d
Explanation: if the argument list is the same, the return types cannot be the incompatible-
[Link] the compiler reports an error “the return type is incompatible with
[Link](int).
54. What is the output of the below code snippet?
class Sweet
{
void price()
{
[Link](“sweet=$10”);
}
}
class Sugar extend Sweet
{
Void price()
{
[Link]();
[Link](“Sugar=$20”);
}
}
Class sugar extends Sweet
{
Void price()
{
[Link]();
[Link](“Sugar =$20”);
}
}
public class JavaInheritance1
{
Public static void main (String[] args)
{
Sugar su =new Sugar();
[Link]();
}
}
a) Sweet =310 Sugar =$20
b) Sweet =$10 Sugar=$10
c) Sweet =$20 Sugar=$20
d) Compiler error
Correct Answer : a
Explanation:
Notice the use of the keyword “super”. Using this keyword ,you can call super class’s methods
and variables.

55. Which SQL Keyword must be used to remove duplicate rows from the result?
a) Delete
b) Unique
c) Distinct
d) Not Exist
Answer: option c
Explanation: Remove the duplicates columns from the result set.

56. Delete r form P


The Above command
a) Deletes a Particular tuple from the relation
b) Deletes the relation
c) clears all the entries from the relation
d) All of the mentioned
Answer: option a
Explanation: Here P gives the condition for deleting specific rows.

57. Examine the description of the EMPLOYEES table:


EmpId int,
LastName varchar (20),
FirstName varchar (20),
DeptId int,
JobCat varchar (20),
Salary int.
Which Statement shows the maximum salary paid in each job category of each department?
a) Select DeptId, JobCat,Max(Salary) From employees where Salary > Max(Salary);
b) Select DeptId, JobCat,Max(Salary) From employees Group by DeptId, JobCat;
c) Select DeptId, JobCat,Max(Salary) From employees;
d) Select DeptId, JobCat,Max(Salary) From employees Group by DeptId;
Answer: b

58. Point out wrong Statement.


a) RANK () returns the rank of each row in the result set of partitioned column
b) DENSE_RANK () is same as RANK () function. Only difference is returns without gaps
c) NTILE () distributes the columns in an ordered partition into specific number of groups
d) ROW_NUMBER () returns the serial number of the row order by specified Column

Answer c:
Explanation: NTILE divides the partitioned result set into specified number of groups in an order.

59. Whic of the following is not ranking function?


a) RANK
b) NTILE
c) ROW_NUMBER
d) All the mentioned
Answer: d
Explanation: Ranking functions are a subset of the built-in functions in SQL Server.

60. Which of the following function is used when you want all tied rows to have the same ranking?
a) RANK
b) NTILE
c) ROW_NUMBER
d) None of the mentioned

Answer: a
Explanation: The Numbers assigned by RANK are not necessarily consecutive.

61. What type of joins needed when you wish to include rows that do not have matching values?
a) Equi-join
b) Natural join
c) Outer join
d) All of the mentioned
Answer: c
Explanation: Outer Join is the only join which shows the unmatched rows.

62. Which of the following statement is true concerning subqueries?


a) Involves the use of an inner and outer query
b) Cannot return the same result as a query that is not subquery
c) Does not start with the word SELECT
d) All of the mentioned

Answer: a
Explanation: Subquery also referred to as an inner query or inner select is SELECT statement
embedded within the data manipulation language (DML) Statement or nested within another
subquery.

63. The following SQL is which type of join:


SELECT CUSTOMER_T. CUSTOMER_ID, ORDER_T. CUSTOMER_ID, NAME,ORDER_ID FROM
CUSTOMER_T,ORDER_T?
a) Equi-join
b) Natural join
c) Outer join
d) Cartesian join
Answer: d
Explanation: Cartesian join is simply the joining of one or more table which returns the product
of all the rows in these tables.

64. Which clause is similar to “Having” clause in Mysql?


a) SELECT
b) WHERE
c) FROM
d) None of the mentioned

Answer: b
Explanation: “WHERE” is also used to filter the row values in MySQL.
65. Which of the following belongs to an “Aggregate function”?
a) Count
b) sum/Avg
c) Min/Max
d) All of the mentioned
Answer: d

66. Which clause is used to with an “aggregate function”?


a) Group by
b) Select
c) Where
d) Both Group by and Where
Answer: a
Explanation: “Group by” is used with aggregate functions.

67. Foreign keys cannot handle delete and updates.


a) True
b) False
Answer: b
Explanation: A foreign key is the one which declares than an index in one table is related to that
in another and place constraints. It is useful for handling deletes and updates along with row
entries.

68. Which key declares that an index in one table is related to that in another?
a) Primary
b) Secondary
c) Foreign
d) cross
Answer: c
Explanation:
In MySQL a foreign key is the one which facilitates index relations across tables. It Declares that
an index in one table is related to that in another and place constraints.

69. Which of the following statement is True about Primary Key?


a) Table integrity is not enforced the primary key.
b) The data in a primary key is always multiple.
c) 900 bytes is the maximum length of a primary key.
d) Null values are allowed in primary keys.
Answer: c
Explanation: We can have up to 16 columns as primary key column and the total size of the key
columns should be less than or equal to 900 bytes.

70. To add a Primary key constraint after table is created which clause is used?
a) Update
b) Add
c) Alter
d) Join
Answer:c
Explanation: ALTER Used to add ,delete/drop or modify columns in the existing table.

71. What is Self-join?


a) Value match in both tables.
b) Value match in Either table.
c) Joins the table to itself.
d) Return the rows in first table multiplied by the rows in the second table.
Answer:c
Explanation: Self -join is a join that can be used to join a table with itself.

72. What is the purpose of index in DB?


a) To enhance the query performance
b) To provide an index to a record
c) To perform fast searches
d) All of the mentioned
Answer: d
Explanation:
A database index is a data structure that improves the speed of data retrieval operations on a
database table at the cost of additional writes.

73. What is true about indexes?


a) Indexes enhance the performance even if that table is updated frequently
b) It makes harder for sql server engines to work to work on index which have large keys
c) It doesn’t make harder for sql server engines to work to work on index which have large keys
d) None of the mentioned
Answer:b
Explanation
It make harder for sql server engines to work to work on index which have large keys

74. How do you find the second highest salary in SQL?


a) Select Max(Salary) as salary from table_name Where salary < (Select Max(Salary) from
table_name);
b) Select Salary from table_name order by Salary DESC limit n-1,1;
c) Select Top 1 Salary from( Select Distinct Top 3 Salary from table_name order by Salary Desc) a
order by Salary;
d) Select Salary from table_name order by Salary DESC limit 2,1;
Answer: a

75. A ___________ is special kind of a store procedure that executes in response to certain action
on the table like insertion,deletion or updation of data.
a) Procedures
b) Triggers
c)Functions
d)None of the mentioned
Answer:b
Explanation:
Triggers are automatically generated when particular operation take place

76. The variable in the triggers are declared using


a) –
b) @
c) /
d) /@
Answer b:
Explanation: Example : declare @empid int; where empid is variable.

77. Triggers enable to enforce data integrity constraints


a) True
b) False
Answer : a
Explanation: in MySQL, trigger can examine or change new data values to be inserted or used to
update a row in table. This enables the enforcement of the data integrity constraints

78. Which Statement is used to remove a trigger?


a) Remove
b) Delete
c) Drop
d) Clear
Answer: c
Explanation: In order to delete a trigger, the DROP TRIGGER Statement is used. The DROP
TRIGGER construct is used by writing the phrase “DROP TRIGGER” followed by the schema name
specification.

79. What is the abc in the following MySQL Statement?


CREATE TRIGGER abc (..) (..) ON def FOR EACH ROW ghi;
a) Trigger name
b) table name
c) trigger statement
d) update statement
Answer: a
Explanation: In MySQL the trigger creation construct is the “CREATE TRIGGER” construct. It
specifies the trigger name the type of statement for which is activated, and the table name and
statement.

80. ________ function return current date and time.


a) SETDATEFIRST
b) SYSDATETIME
c) Cert_ID
d) GETDATE
Answer: d
Explanation: GETDATE function is used to obtain the current system date and time. Although
GETDATE does not have any input parameters, you still need to include the parentheses in your
code because that’s how SQL server typically identifies functions.

81. Which of the following is not a mathematical function?


a) ATN2
b) POWER
c) PI
d) CEIL
Answer: d
Explanation: SQL server has CEILING function to get the smallest integer grater than the
specified expression.

82. Text and Image functions are________


a) nondeterministic
b) deterministic
c) table valued
d) all of the mentioned
Answer :a
Explanation: Text and image functions are nondeterministic. This means they do not always
return the same result every time they are called, even with the same set of input values.

83. If there is two table one table is family table and another one is Bills table. family table have the
two columns family name and customer id and bill table have two column customer id, amount.
please find the family name which have highest bill in the table.
Correct the Query ?
SELECT [Link], _____([Link])
FROM family
_______ bills
ON f. customerId = b. customerId
GROUP BY [Link]

a) MIN, JOIN
b) MAX, INNER JOIN
c) AVG, FULL JOIN
d) None
Answer: b
Explanation: INNER JOIN (Combining rows that have matching values in two or more tables.)

84. If there is two table one table is customer table and another one is account table. customer
table have the two columns name and customer id and account table have three column
customer id, balance, account id. print the customer id and the sum of the balance.
Fill the blanks to achieve the above scenario?
SELECT customer id, sum(balance) total from (select customer id, name from customer ______
select customer id, balance from account) t group by customer id
a) Union All
b) Union
c) None
d) Intersect
Answer : a
Explanation: Union all operator is used to combine the result set of 2 or more select statements.

You might also like