Uploaded by Mustafa Rakhmetov

48p

advertisement
1. Which of the following is a mistake from the given code? - None of the above
2. Say that there are three classes: Computer, AplleComputer, and IBMComputer. What are the
likely relationships between these classes? - Computer it the superclass, AplleComputer
and IBMComputer are subclasses of Computer.
3. Use picture above to answer the question. Which of the following lines will give errors? - 1, 7
4. Which oops concept is used as reuse mechanism? - Inheritance
5. What will be the output of following program? - No story With Story Good Movie
6. Encapsulation is used to control variable assignment? - True
7. It is a mechanism of wrapping the data and code acting on the data together as a single unit Encapsulation
8. There is superclass Person which has method work(). Class Fighter extends class Person and
has method fight(). Which of the following statements is false? - Person can fight
9. What is an object? - It is an instance of class
10. Inheritance is used when the relationship between two classes _____ - is-a
11. How many objects of a given class can there be in a program? - As many as the program
needs.
12. When subclass has its own implementation, different from superclass version it is called
_____ - Method Overriding
13. In other words encapsulation is: Data hiding
14. Which of the following is True in JAVA? - One class can implement more than one interface
15. Use picture above to answer the question. Which of the following lines will give errors? - 7
16. Which OOP principle enables you to deal in generalities and let the execution-time
environment handle the specifics? - Polymorphism
17. Encapsulation is a mechanism of wrapping _____ and code acting on _____ together as a
single unit. Fill the missing part. - variables, methods
18. What method is implemented in Cosmic Superclass? - toString()
19. Which of these is NOT an advantage of OOP? - Less program size.
20. What’s the extension for a compiled Java file? - .class
21. What is constructor in Java? Constructor is similar to a method but is called
implicitly by the new operator to initialize an object's instance variables when the object
is created
22. Which of the following is false about encapsulation? - In encapsulation the methods of the
class will be hidden
23. Use picture above to answer the question. Which of the following lines will give errors? None
24. What do we call a simple function that called using reference variable? - Not constructor Not
Field
25. Java supports only single inheritance, in which each class is derived from exactly one direct
superclass. TRUE or FALSE? - TRUE
26. Which of these can be used only when an object of that class type has been created - Nonstatic members
27. When the subclass method is intended as a replacement of the superclass method. - (not
aggregation)
28. What can be accessed by members of the superclass, of its subclasses and other classes in the
same package? - superclass’s protected members
29. Which of these types is non-primitive? - int[]
30. What is the reason to use method overriding? - It is used whenever subclass needs specific
implementation of superclass method
31. What is protected access modifier? 32. Which of these is correct way of inheriting class A by class B? - class B extends A {}
33. What allows you to save time during development by basing new classes on existing proven
and debugged high-quality software? - Inheritance
34. If data members are private, what can we do to access them from the class object? - Create
public member functions to access those data members
35. A class Animal has a subclass Mammal. Which of the following is true: Mammal can have
no other parent than Animal.
36. Which OOPS concept means exposing only necessary information to the calling functions? Encapsulation
37. Public static void main(String args[]) (which part of the code above responsible for method or
variable not being an instance related but class related?) - static
38. One class could have only one constructor - False
39. Aggregation in Java is a relationship between two entities, where the composed object cannot
exist without the other entity. - False
40. Which of these is a reference to the parent class object? - super
41. Which of this keyword must be used to inherit a class? - extends
42. What is the main difference of an interface from abstract class? - An interface contains only
abstract methods
43. Which of the following statements is false? - Static methods can be used only after object of
the class type has been created
44. In other words encapsulation is: Data hiding
45. Which of the following statements are true for inheritance in Java? - (not The “extend”
keyword is used to extend a class in java.)
46. What is a composition? - (not a. It is a relationship between objects where one is basing an
object or class upon another object)
47. Which of the following is a mistake from the given code? -
48. What is an aggregation? - It is a relationship between objects, where both the entries can
survive individually which means ending one entity will not effect the other entity
49. In order to use encapsulation inside a class, method and variable must be: variable-private ,
method-public
50. What are the advantages of OOP? - Reusability, Efficiency, Extensibility, Refactoring
51. What kind of programming languages is Java? - Object-Oriented Programming Language
52. What is described in the following statement? - (not Data manipulation)
53. Which class is a class that inherits a method or methods from a superclass? - Sub class
54. What is FALSE about a constructor? - (not The compiler will insert a default constructor if no
other constructors exist) ()
55. Which is correct syntax for creating an object of Class in Java? - classname objectname = new
classname();
56. Which of these is NOT the idea behind an Encapsulation? - It enables you to “program in
the general” rather than “program in the specific”
57. An inheritance is … the mechanism by which one class is allowed to inherit the features
(fields and methods) of another class.
58. What are the relationships in the following sentences? A computer owns a CPU. A computer
has a user. - composition, aggregation
59. Which of these is the main idea behind “Polymorphism”? - (not It provides…)
60. What is TRUE about objects’ association? - Aggregation is when objects are using “has-a”
relationship, whereas, composition is when objects are using “is-part-of” relationship
61. A public method that reads and returns data from one or more private instance variables Accessor method
62. ___ method cannot be overridden by a subclass - final
63. What type of inheritance does Java have? - single inheritance
64. What is a direct superclass of monkey in the following scheme? animal - mammal - monkey gorilla - mammal
65. What kind of constructors exist in Java? 66. What is called using this() - Current class’s no-argument constructor
67. What is TRUE about private member variables? 68. What is FALSE about casting in Java? - One subclass reference can be casted to absolutely
another subclass reference of the same direct superclass
69. What is called using super() - Super class’s no-argument constructor
70. Which class is called as “Cosmic superclass” - Object
71. Call to super() must be first statement in subclass constructor. What will happen if you don’t
call it explicitly? - (not The compiler would attempt to insert a call to Object class’s
constructor
72. What do we use to define the behavior of an object? - Method
73. Which of the following can be static? - Class
74. Java is a/an - Object-oriented language
75. Which of these access specifiers must be used for main() method? - public
76. Which of the following is not the name of a Java primitive data type? - String
77. What is the return type of a method that does not return any value? - void
78. Which of these class in superclass of every class in Java? - Object class
79. A class can have only one constructor - False
80. Which of the following is an incorrect statement about packages? 81. Public static void main(String args[]) (which part of the code above responsible for method
being taken as a starting point of an application by JVM?) - main
82. What is the incorrect statement about static identifier? 83. Which of this access specifies can be used for a class so that its members can be accessed by a
different class in the same package? - All of the mentioned
84. What do we use to define the state of an object? - Field
85. Non-static fields and methods cannot be called from static methods - True
86. What is the incorrect statement about primitive data types? - Primitive data types can not be
directly used in any program. We have to create a user-defined data type and then use
it.
87. Which of these keywords is used to make a class? - Class
88. A private member of a class is visible to: members of same class
89. Non-static fields and methods can be called from static methods - False
90. Say that a particular item of data does not use a primitive data type. What must it be? - An
object
91. public static void main(String args[]) (which part of the code above responsible for method
being accessible by any class?) - public
92. Which of the following statements is correct? - Public method is accessible to all other
classes in the hierarchy
93. Which method can be defined only once in a program? - main method
94. Constructor can return a value - False
95. When the subclass method is intended as a replacement of the superclass method - overriding
96. Which of the following is about Interface segregation principle? - Many client-specific
interfaces are better than one general-purpose interface.
97. What can help to achieve multiple inheritance in Java? - Interfaces
98. What type of inheritance does Java have? - single inheritance
99. Which of the below is not a valid classification of design pattern - Observer patterns
100.
Which of the following principles asks us to implement Is-A relationship carefully? liskov substitution principle
101.
Which of the following is about Liskov substitution principle? - Objects in a program
should be replaceable with instances of their subtypes without altering the correctness of
that program.
102.
Choose correct type of polymorphism for: Method overloading Method overriding - 1.
compile-time polymorphism and 2. runtime polymorphism
103.
What is the correct option to create a statement? - Statement stmt =
comn.create.Statement();
104.
What the following statement is about? - A.class shouldn’t be forced to implement
undeeded methods of an interface
105.
Which class is used to get the connection to database? -DriverManager
106.
Which of the following is a mistake from the given code? - Class Quadrangle should
extend Shape instead of implementing is
107.
In order to handle exceptions in java we use: - try{...}catch(...){...}
108.
Aggregation in Java is a relationship between two entities, where the composed object
cannot exist without the other entity. - True
109.
The built-in base in Java, which is used to handle all exceptions is - throwable
110.
Which is the benefit of using interface instead of abstract class in Java? - it is possible to
implement several interfaces in one class
111.
Which of the following statement is about? - In order to extend the functionality, it is
suggested to add a new code instead of changing the existing one
112.
What the following statement is about? - A class should have only one particular
responsibility
113.
What does “S” in the SOLID stand for? - single responsibility principle
114.
Non-static fields and methods can be called from static methods - False
115.
What is the main difference of abstract class from the concrete class? - It is not allowed
to instantiate an object using an abstract class
116.
Which of the following is about Single-responsibility principle? - A class should only
have a single responsibility…
117.
Which of the following is about Dependency inversion principle? - Software entities ...
should be open for extension, but closed for modification
118.
What the following statement is about? -
119.
What is output of the following program if input is t 0? - NumberFormatException!
EndtermQuiz
Question 1
Correct
Mark 1.00 out of
1.00
Question 2
Correct
Mark 1.00 out of
1.00
Question 3
Correct
Mark 1.00 out of
1.00
Started on Wednesday, 23 February 2022, 7:00 PM
State Finished
Completed on Wednesday, 23 February 2022, 7:20 PM
Time taken 19 mins 59 secs
Marks 14.65/25.00
Grade 58.60 out of 100.00
The principle of component cohesion is _____
Select one:
a. Open/Closed
b. Common Closure Principle 
c. Interface Segregation
d. Liskov Substitution
Your answer is correct.
The correct answer is: Common Closure Principle
What is JDBC?
Select one:
a. None
b. John Dough Base Code
c. Java Design Better Connectivity
d. Java Database Connectivity 
Your answer is correct.
The correct answer is: Java Database Connectivity
The principle of component cohesion is _____
Select one:
a. Dependency Inversion
b. Common Reuse Principle 
c. Interface Segregation
d. Liskov Substitution
Your answer is correct.
The correct answer is: Common Reuse Principle
23.02.2022, 19:34 EndtermQuiz: Attempt review
https://moodle.astanait.edu.kz/mod/quiz/review.php?attempt=158219&cmid=42887#question-175943-2 2/7
Question 4
Partially correct
Mark 0.50 out of
1.00
Question 5
Incorrect
Mark 0.00 out of
1.00
Question 6
Correct
Mark 1.00 out of
1.00
Question 7
Incorrect
Mark 0.00 out of
1.00
Which of the following is true about Lambda expressions?
Select one or more:
a. assign lambda expressions to variables for later use
b. lambda expressions enable you to create methods that can be treated as data 
c. you can pass lambda expressions as arguments to other methods 
d. return lambda expressions from methods
Your answer is partially correct.
You have correctly selected 2.
The correct answers are: you can pass lambda expressions as arguments to other methods, return
lambda expressions
from methods, assign lambda expressions to variables for later use, lambda expressions enable
you to create methods
that can be treated as data
The diamond problem could occur when we deal with single inheritance
Select one:
True 
False
The correct answer is 'False'.
The principle of component cohesion is _____
Select one:
a. Open/Closed
b. Reuse/Release Equivalence Principle 
c. Liskov Substitution
d. Single Responsibility
Your answer is correct.
The correct answer is: Reuse/Release Equivalence Principle
What is Fragility?
Select one:
a. things break in unrelated places
b. every change affects many other parts 
c. cannot reuse code outside of its original context
Your answer is incorrect.
The correct answer is: things break in unrelated places
23.02.2022, 19:34 EndtermQuiz: Attempt review
https://moodle.astanait.edu.kz/mod/quiz/review.php?attempt=158219&cmid=42887#question-175943-2 3/7
Question 8
Correct
Mark 1.00 out of
1.00
Question 9
Partially correct
Mark 0.75 out of
1.00
Question 10
Correct
Mark 1.00 out of
1.00
Question 11
Incorrect
Mark 0.00 out of
1.00
Interfaces also may contain public default methods with concrete default implementations
Select one:
True 
False
The correct answer is 'True'.
Which one(s) is true about Interface Segregation Principle?
Select one or more:
a. Changing a method must affect on unrelated class
b. Clients shouldn't be forced to depend on methods they do not use 
c. A client should never be forced to implement an interface that it doesn't use 
d. Make fine-grained interfaces with specific methods
e. A client should never depend on anything more that the method which is used 
Your answer is partially correct.
You have correctly selected 3.
The correct answers are: Make fine-grained interfaces with specific methods, A client should
never be forced to
implement an interface that it doesn't use, Clients shouldn't be forced to depend on methods they
do not use, A client
should never depend on anything more that the method which is used
Static methods contain the complete definition of the function
Select one:
True 
False
The correct answer is 'True'.
Interfaces specify how operations are performed when an implementing class does not override
the methods
Select one:
True
False 
The correct answer is 'True'.
23.02.2022, 19:34 EndtermQuiz: Attempt review
https://moodle.astanait.edu.kz/mod/quiz/review.php?attempt=158219&cmid=42887#question-175943-2 4/7
Question 12
Partially correct
Mark 0.40 out of
1.00
Question 13
Partially correct
Mark 0.67 out of
1.00
Question 14
Partially correct
Mark 0.67 out of
1.00
Which one(s) is true about the Reuse/Release Equivalence Principle
Select one or more:
a. Architects would do well to group reusable classes together into packages
b. Create sensible packages
c. One criteria for grouping classes into packages is reuse
d. Classes and modules that are formed into a component must belong to a cohesive group 
e. The granule of reuse is the granule of release 
Your answer is partially correct.
You have correctly selected 2.
The correct answers are: The granule of reuse is the granule of release, Create sensible packages,
One criteria for grouping
classes into packages is reuse, Classes and modules that are formed into a component must
belong to a cohesive group,
Architects would do well to group reusable classes together into packages
Which one(s) is true about the Dependency Inversion Principle?
Select one or more:
a. It states that the high-level module must not depend on the low-level module, but they should
depend on
abstractions 
b. It should not be possible to change an implementation easily without altering high-level code
c. The code that implements high-level policy should not depend on the code that implements
low-level details.
d. Depend on abstractions, not on concretions 
Your answer is partially correct.
You have correctly selected 2.
The correct answers are: Depend on abstractions, not on concretions, It states that the high-level
module must not
depend on the low-level module, but they should depend on abstractions, The code that
implements high-level policy
should not depend on the code that implements low-level details.
Which one(s) is true about Common Reuse Principle?
Select one or more:
a. Don’t force users of a component to depend on things they don’t need
b. Before removing the dependency make sure that you depend on every class of that component
c. Classes and modules that tend to be reused together belong in the same component 
d. A dependency upon package is a dependency upon everything within a package 
Your answer is partially correct.
You have correctly selected 2.
The correct answers are: Don’t force users of a component to depend on things they don’t need,
Classes and modules
that tend to be reused together belong in the same component, A dependency upon package is a
dependency upon
everything within a package
23.02.2022, 19:34 EndtermQuiz: Attempt review
https://moodle.astanait.edu.kz/mod/quiz/review.php?attempt=158219&cmid=42887#question-175943-2 5/7
Question 15
Partially correct
Mark 0.50 out of
1.00
Question 16
Incorrect
Mark 0.00 out of
1.00
Question 17
Correct
Mark 1.00 out of
1.00
Question 18
Partially correct
Mark 0.50 out of
1.00
Which one(s) is true about Single Responsibility Principle?
Select one or more:
a. Expectations are often exaggerated
b. you make sure that your class or module has high cohesion
c. A class should have only one reason to change 
d. class should have only one job 
Your answer is partially correct.
You have correctly selected 2.
The correct answers are: A class should have only one reason to change, class should have only
one job, Expectations are
often exaggerated, you make sure that your class or module has high cohesion
What is Rigidity?
Select one:
a. things break in unrelated places 
b. every change affects many other parts
c. cannot reuse code outside of its original context
Your answer is incorrect.
The correct answer is: every change affects many other parts
Static Methods in Interface are those methods, which are defined in the interface with the
keyword static
Select one:
True 
False
The correct answer is 'True'.
Which one(s) is true about Open/Closed Principle?
Select one or more:
a. Extend functionality by adding new code, instead of changing existing one 
b. Separate the behaviors, therefore, the system will not be broken and easily extended
c. Objects or entities should be open for extension, but closed for modification 
d. You should be able to extend a class without modifying it
Your answer is partially correct.
You have correctly selected 2.
The correct answers are: You should be able to extend a class without modifying it, Objects or
entities should be open for
extension, but closed for modification, Extend functionality by adding new code, instead of
changing existing one,
Separate the behaviors, therefore, the system will not be broken and easily extended
23.02.2022, 19:34 EndtermQuiz: Attempt review
https://moodle.astanait.edu.kz/mod/quiz/review.php?attempt=158219&cmid=42887#question-175943-2 6/7
Question 19
Incorrect
Mark 0.00 out of
1.00
Question 20
Correct
Mark 1.00 out of
1.00
Question 21
Correct
Mark 1.00 out of
1.00
Question 22
Correct
Mark 1.00 out of
1.00
Generics represent an anonymous method—that is, a method without a name.
Select one:
True 
False
The correct answer is 'False'.
SOLID term was introduces by
Select one:
a. Tesla
b. Elon Musk
c. Robert Martin 
d. Donald Knuth
Your answer is correct.
The correct answer is: Robert Martin
What is Immobility?
Select one:
a. every change affects many other parts
b. things break in unrelated places
c. cannot reuse code outside of its original context 
Your answer is correct.
The correct answer is: cannot reuse code outside of its original context
What is SOLID?
Select one:
a. all of the answers
b. design patterns 
c. classes
d. methods
Your answer is correct.
The correct answer is: design patterns
23.02.2022, 19:34 EndtermQuiz: Attempt review
https://moodle.astanait.edu.kz/mod/quiz/review.php?attempt=158219&cmid=42887#question-175943-2 7/7
Question 23
Partially correct
Mark 0.67 out of
1.00
Question 24
Incorrect
Mark 0.00 out of
1.00
Question 25
Incorrect
Mark 0.00 out of
1.00
Which one(s) is true about the Common Closure Principle?
Select one or more:
a. The more packages that change in any given release, the greater the work to rebuild, test, and
deploy the release
b. Separate into different components those classes that change at different times and for
different reasons 
c. Classes that change together, don't belong together
d. Gather into components those classes that change for the same reasons and at the same times 
Your answer is partially correct.
You have correctly selected 2.
The correct answers are: Gather into components those classes that change for the same reasons
and at the same times,
Separate into different components those classes that change at different times and for different
reasons, The more
packages that change in any given release, the greater the work to rebuild, test, and deploy the
release
The core problem of the diamond is that an object of type D could have more than two
implementation of the same
method
A
/\
BC
\/
D
Select one:
True 
False
The correct answer is 'False'.
Which one(s) is true about Liskov Substitution Principle?
Select one or more:
a. Every part of code should get the expected result whatever class instance is sent
b. Let φ(x) be a property provable about objects of x of type T. Then φ(y) should be provable for
objects y of type S
where S is a subtype of T.
c. to build software systems from interchangeable parts, those parts must adhere to a contract that
allows those parts
to be substituted one for another
d. Derived classes must not be substitutable for their base classes without consumer knowing it 
Your answer is incorrect.
The correct answers are: Every part of code should get the expected result whatever class
instance is sent, Let φ(x) be a
property provable about objects of x of type T. Then φ(y) should be provable for objects y of
type S where S is a subtype
of T., to build software systems from interchangeable parts, those parts must adhere to a contract
that allows those parts
to be substituted one for another
1. Which of these is NOT the idea behind an Encapsulation? - It enables you to “program in
the general” rather than “program in the specific”
2. What type of inheritance does Java have? - single inheritance
3. Which of these is a reference to the current object? – this
4. What is FALSE about casting in Java? - One subclass reference can be casted to
absolutely another subclass reference of the same direct superclass
5. Non-static fields and methods can be called from static methods – False
6. In order to handle exceptions in java we use: - try{...}catch(...){...}
7. What is an object? - It is an instance of class
8. What is the benefit of using interface instead of abstract class in JAVA - is: it is possible
to implement several interfaces in one class
9. What will be the output of following program?
class Producer
{
void story()
{
System.out.println("No story");
}
}
class Director extends Producer
{
void story()
{
super.story();
System.out.println("With story");
}
}
class Hero extends Director
{
void story()
{
super.story();
System.out.println("Good Movie");
}
}
public class Movie
{
public static void main(String args[])
{
Hero hero=new Hero();
hero.story();
}
}
Answer: No story
With story
Good Movie
10. What is the main difference of abstract class from the concrete class? - It is not allowed
to instantiate an object using an abstract class
11. Block finally in exception handling executes: - Always
12. Choose correct type of polymorphism for:
1 Method overloading
2 Method overriding
Answer: 1. compile-time polymorphism and 2. runtime polymorphism
13. What is the main difference of an interface from abstract class? - An interface contains
only abstract methods
14. An inheritance is ... - the mechanism by which one class is allowed to inherit the features
(fields and methods) of another class.
15. To prevent any method from overriding, we declare the method as, - final
16. What is TRUE about private member variables? - Private member variables can be
accessed indirectly using their accessors and mutators
17. When subclass has its own implementation, different from superclass version it is called Method Overriding
18. What should a programmer do if the class partially implements the interface in JAVA? Add abstract keyword in the declaraion of this class
19. Which of these can be used only when an object of that class type has been created Non-static members
20. What can help to achieve multiple inheritance in Java? - Interfaces
21. Java supports only single inheritance, in which each class is derived from exactly one
direct superclass. TRUE or FALSE? – TRUE
22. Which of the following is false about encapsulation? - In encapsulation the methods of
the class will be hidden
23. What kind of constructors exist in Java? - No argument and parameterized constructors
24. Which of these is the main idea behind "Polymorphism"? - it enables you to “program in
the general” rather than “program in the specific”
25. One class could have only one constructor – FALSE
26. Choose the correct structure for exception handling - try { ... } catch(exception) { ... }
27. Which of these types is non-primitive? - int[]
28. Which of these is a reference to the parent class object? – super
29. Which of this keyword must be used to inherit a class? – Extends
30. Which of these is FALSE about static members? - A memory for storing static members
is allocated during the object creation
31. The built-in base class in Java, which is used to handle all exceptions is – Throwable
32. It is a mechanism of wrapping the data and code acting on the data together as a single
unit – Encapsulation
33. Which of the following is not the name of a Java primitive data type? – String
34. Which of the following is TRUE in JAVA? - One class can implement more than one
interfaces
35. What is the return type of a method that does not return any value? - void
36. Static fields and methods can be called from non-static methods – True
37. Which of these is NOT an advantage of OOP? - Less program size
38. What is the reason to use try-catch block? - For exception handling
39. What is FALSE about a constructor? - A constructor is a public method of a class which
can be explicitly called using a class object
40. What allows you to save time during program development by basing new classes on
existing proven and debugged high-quality software? – Inheritance
41. Call to super() must be first statement in subclass constructor. What will happen if you
don’t call it explicitly? - The compiler would attempt to insert a call to the superclass’s
default constructor
42. What is protected access modifier? - It gives permission to access current member only
from subclasses or from the same package
43. Which OOP principle enables you to deal in generalities and let the execution-time
environment handle the specifics? – Polymorphism
44. Find a definition of Casting in java - Casting is the process of converting one data type to
another
45. What is an advantage of Encapsulation? - a. All of the above
b. An outside class can not access the data members of that class.
c. With encapsulation we can make the data as read-only or write-only as we require it to
be.
d. It allows the programmer to use the existing code again and again in an effective way.
The relation between Car and Owner or BankAccount and Customer is example for
Select one:
a. Association
b. Aggregation
c. None
d. Composition
Which of the following best defines a class?
Select one:
a. Parent of an object
b. Blueprint of an object
c. Instance of an object
d. Scope of an object
Which among the following best describes constructor overloading?
Select one:
a. Defining more than one constructor in single class
b. Defining more than one constructor in single class with different signature
c. Defining destructor with each constructor
d. Defining one constructor in each class of a program
Default constructor initializes all data members as ___________
Select one:
a. All numeric member with some garbage values and string to random string
b. All numeric member with zero and strings to null
c. All numeric member with some garbage values and string to null
d. All numeric member with zero and strings to random value
class Base {
public void test() {
}
}
class Base1 extends Base {
public void test() {
System.out.println("Base1");
}
}
class Base2 extends Base {
public void test() {
System.out.println("Base2");
}
}
class Test {
public static void main(String[] args) {
Base obj = new Base1();
((Base2) obj).test(); // CAST
}
}
Select one:
a. The program will print the following: Base1.
b. The program will result in an exception (ClassCastException).
c. The program will print the following: Base2.
d. The compiler will report an error in the line marked with comment CAST.
What are public, private & protected in OOP?
Select one:
a. Interfaces
b. Method signature
c. Classes
d. Access Modifiers
A class can inherit instance variables and methods from a more abstract superclass.
Select one:
a. True
b. False
Which statement is incorrect for static methods
Select one:
a. Static fields and methods can be used directly using a class type
b. Static fields and methods cannot be called from non-static methods
c. Non-static fields and methods cannot be called from static methods
d. Static fields and methods can be called from non-static methods
Which among the following is false for a constructor?
Select one:
a. Constructors doesn’t have a return value
b. Constructors are always user defined
c. Constructors are overloaded with different signature
d. Constructors may or may not have any arguments being accepted
What is the wrong signature for the Demo class constructor?
Select one:
a. Demo1(Demo demo) {..}
b. Demo() {}
c. Demo(Demo1 demo){…}
d. Demo (int a) {…}
The relation between Car and Owner or BankAccount and Customer is example for
Select one:
a. Association
b. Aggregation
c. None
d. Composition
For constructor overloading, each constructor must differ in ___________ and __________
Select one:
a. Number of arguments and type of arguments
b. Return type and definition
c. Return type and type of arguments
d. Number of arguments and return type
Can we overload constructor in derived class?
Select one:
a. No
b. Yes, but only from abstract method
c. Yes
d. Yes, but only for indirect parent
An interface cannot have an child.
Select one:
a. False
b. True
Which of the following best defines a class?
Select one:
a. Parent of an object
b. Blueprint of an object
c. Instance of an object
d. Scope of an object
What are public, private & protected in OOP?
Select one:
a. Interfaces
b. Method signature
c. Classes
d. Access Modifiers
Which statement is incorrect for static methods
Select one:
a. Static fields and methods can be used directly using a class type
b. Static fields and methods cannot be called from non-static methods
c. Non-static fields and methods cannot be called from static methods
d. Static fields and methods can be called from non-static methods
What is it called where child object gets killed if parent object is killed?
Select one:
a. Aggregation
b. Association
c. Composition
d. Encapsulation
а)
b)
c)
b)
d)
Call to super() must be first statement in subclass constructor. What will happen if
you don’t call it explicitly?
The compiler would attempt to insert a call to the superclass’s default constructor
What allows you to save time during program development by basing new classes
on existing proven and debugged high-quality software?
Inheritance
What is the main difference of abstract class from the concrete class?
An abstract class contains only abstract methods
What is an aggregation?
It is a relationship between objects, where both the entries can survive individually
which means ending one entity will not effect the other entity
What is called using super()
Super class`s no-argument constructor
What is a composition?
It is a relationship between objects where the composed object cannot exist
without the other entity
What is the main difference of an interface from abstract class?
An interface contains only abstract methods
How do you call a group of related methods with empty bodies?
Abstraction
What is TRUE about objects` association?
Aggreagation is when objects are using "has-a" relationship, whereas, composition
is when objects are using "is-part-of" relationship
In the example code fragment shown below:public abstract class Test { // . . . more
class code
No object of type Test can ever be created
[Quadrangle4]Which of the following is a mistake from the given code? (IT IS
RECOMMENDED TO READ ANSWER OPTIONS FIRST)
Class Quadrangle must implement method area() of Shape
What is FALSE about casting in Java?
One subclass reference can be casted to absolutely another subclass reference of
the same direct superclass
What is an object?
It is an instance of class
What is described in the following statement?_"A programmer using a method that
you have defined does not need to know the details of the code in the body of the
method"_
Data hiding
If data members are private, what can we do to access them from the class object?
Create public member functions to access those data members
What is called using this()
Current class`s no-argument constructor
A class that cannot be subclassed is called a ________.
Final class
[Quadrangle 2]Which of the following is a mistake from the given code? (IT IS
RECOMMENDED TO READ ANSWER OPTIONS FIRST)
Аслан сказал Да
This class cannot be used to instantiate objects
Abstract class
Which of the following is FALSE about abstract classes in Java
A class can inherit from multiple abstract classes
What is PROTECTED access modifier?
It gives permission to access current member only from subclasses or from the
same package
What is FALSE about a constructor?
A constructor is a public method of a class which can be explicitly called using a
class object
What is TRUE about private member variables?
Private member variables can be accessed indirectly using their accessors and
mutators
When a reference variable of a Parent class refers to the object of the Child class,
then it is known as
Upcasting
What is the reason to use try-catch block?
For exception handling
What is the reason to use method overriding?
It is used whenever subclass needs specific implementation of superclass method
Find a definition of Casting in java
Casting is the process of converting one data type to another
It is a mechanism of wrapping the data and code acting on the data together as a
single unit
Encapsulation
An inheritance is ...
the mechanism by which one class is allowed to inherit the features (fields and
methods) of another class.
In other words encapsulation is:
Data hiding
How many errors in the code below? (write single integer
number)PUBLIC Employee{ PRIVATE String name; PRIVATE
PUBLIC
FLOAT salary;
Employee(String name, FLOAT salary){ THIS.name = Name;
THIS.salary =
salary; } PUBLIC FLOAT calcPay() {
RETURN salary /
24; }} CLASS Sales EXTENDS Employee{ PRIVATE FLOAT
commission; PRIVATE totalSa
SUPER(name, salary); }
les; PUBLIC Sales(String name, FLOAT salary){
}
2 If
A is a class.....B and C are interfaces, what is the proper signature for class A to
extend interfaces B and C?
public class A implements B, C {}
[Quadrangle 2] Which of the following is a mistake from the given code? (IT IS
RECOMMENDED TO READ ANSWER OPTIONS FIRST)
Class Quadrangle must be abstract
1. A class should have only one reason to change is definition of which principle?
Answer: SRP
2. Ability to change behaviour of the class without making change in class itself is
property of which design principle?
Answer: OCP
3. Class Circle is subclass of Shape, class Shape has method isFilled() that checks if
shape is filled or not. If you override method isFilled() in class Circle and you will
throw exception when radius of the circle is less than or equal to 0 which design
principle you are breaking?
Answer: LSP
4. Class Employee has method salary(). If I create another class
EmployeeSalaryUpdate that extends from Employee and will override salary()
method to add bonuses for overtime work which principle I will follow?
Answer: OCP
5. Consider some class HashMap<K,V>, what is correct way to instantiate object of this
class?
Answer: HashMap<Integer,String> map = new
HashMap<Integer,String>();
6. Entities should be open for extension, but closed to modifications is definition of
which principle?:
Answer: OCP
7. Fill the gaps: Block finally is executed ______ try-catch block ______
Answer: before, only when there is no exception
8. Generic types can be placeholders for:
Answer: Reference data types
9. How we call problems that rises when we are running programs?
Answer: Exceptions
10. How you can display the exception message to the console?
Answer: In catch block using instance of Exception class print the instance in the
body of the block
11. In following lambda expression: "Subtraction sub1 = (x, y) -> x-y;" how we can trigger
it? Assume interface Subtraction has single method "int subtract(int f, int z)".
Answer: sub1.subtract(10,5);
12. In JDBC you need to use ResultSet…
Answer: to get all values from a table and store them
13. In main method: "public static void main(String[] args)", what is return type?
Answer: void
14. Are ResultSets updateable?
Answer: Yes, but only if we indicate a concurrency strategy when executing the
statement, and if the driver and database support this option.
15. Can we keep other statements in between try, catch and finally blocks?
Answer: No
16. Can we override a super class method which is throwing an unchecked exception
with checked exception in the sub class?
Answer: No
17. Can we throw an exception manually?
Answer: Yes
18. Can we write only try blocks without catch blocks?
Answer: Yes, but it is required to add finally block
19. Does finally block get executed If either try or catch blocks are returning the
control?
Answer: Yes
20. Exception generated in try block is caught in ______ block.
Answer: catch
21. Exceptions are mainly caused by the application itself. For example,
NullPointerException occurs when an application tries to access null object.
Answer: True
22. Exceptions are mainly caused by the environment in which an application is
running. For example, OutOfMemoryException happens when Java runs out of
memory
Answer: False
23. JDBC is a Java API that is used to connect and execute query to the database
Answer: True
24. Parameterized queries can be executed by?
Answer: PreparedStatement
25. Parameterized queries in JDBC can be executed by?
Answer: PreparedStatement
26. Select the package in which JDBC classes are defined?
Answer: sql
27. Select the packages in which JDBC classes are defined?
Answer: sql and javax.sql
28. It is possible to invoke methods at runtime irrespective of the access specifier
(private/public) with the use of some API:
Answer: True
29. The Java feature, "write once, run anywhere", is termed as
Answer: Platform independent
30. The statement: "Reflection exists only in java programming language" is:
Answer: True
31. Dependency Inversion Principle stands that:
Answer: Code should depend on abstraction
32. Interface Segregation Principle stands for:
Answer: Object shouldn't be forced to implement an interface that it doesn't use
33. L in SOLID stands for:
What is used to execute parameterized query?
Answer: PreparedStatement interface
1. There are two types of exceptions in java: checked and unchecked (runtime)
exceptions:
Answer: True
2. What is false regarding statements in JDBC?
Answer: Statement can accept parameters at runtime.
3. When a reference variable of a Parent class refers to the object of the Child class,
then it is known as
Answer: Upcasting
4. Which of these is NOT an advantage of OOP?
Answer: Less program size.
5. What is not considered as a Design principle?
Answer: High cohesion
6. Which of these is FALSE about static members?
Answer: A memory for storing static members is allocated during the object
creation
7. Which of the following is false regrding lambda expressions:
Answer: it is not possible to return lambda expressions from methods
8. Which of these keywords is used to manually throw an exception?
Answer: throw
9. What will be the output of the following Java code?public class Shape { public
return 1; }}public class Square extends Shape { public
int area( ){
int area(
return 2; }}class Main( ) { public static void main(String[
){
] args){
Shape shape =
Square square = new Square( );
square =
new Shape( );
shape;
System.out.println(square.area( )); }}
Answer: Compilation Error
10. What is TRUE about Interface?
Answer: All of the above
11. In case of the following example,what will be result of the code, if class Dog
extends class Animal: Dog d = new Dog();//syntax of upcasting
System.out.println(d instanceof Animal);
Answer: True
12. Which of these is NOT the idea behind an Encapsulation?
Answer: It enables you to “program in the general” rather than “program in the
specific”
13. What will be the output of the following Java code?public class Shape { public
int
area() { return 1; }}public class Square extends Shape { public int area() {
return 2; }}public class Rectangle extends Shape { public int area() { return 3;
}}class Main() { public static void main(String[] args) { Shape shape = new
Shape(); Square square = new Square(); Rectangle rect = new Rectangle(); rect
=
(Rectangle)square; System.out.println(square.area()); }}
Answer: Compilation failure
14. Which of the following contains only unimplemented methods?
Answer: Interface
15. What will be the correct option of the following Java code snippet? interface
ICust {...} class RegularCustomer implements ICust {...} class OneTimeCustomer
implements ICust {...}
Answer: ICust can be replaced with RegularCustomer
16. ______ is a Java API that is used to connect and execute query to the
database
Answer: JDBC
17. What are the major components of the JDBC?
Answer: DriverManager, Driver, Connection, Statement, and ResultSet
18. What is the correct sequence to create a database connection?i.Import JDBC
packages.ii. Establish the connection.iii. Define the connection URL.iv. Execute a
query.v. Create a statement object.vi. Close the resultset and statement
objects.vii. Process the resultset.viii. Close the connection.
Answer: i, iii, ii, v, iv, vii, vi, viii
19. Which of the following is correct about Java 8 lambda expression?
Answer: Both of the above.
Which of these keywords is not a part of exception handling?
What will be the correct option of the following Java code snippet? interface ICust {...} class
RegularCustomer implements ICust {...} class OneTimeCustomer implements ICust {...}
ICust can be replaced with RegularCustomer
Which of the following is false regrding lambda expressions:
Select one:
it is not possible to return lambda expressions from methods
Which of these is NOT an advantage of OOP?
Select one:
Less program size.
What is false regarding statements in JDBC?
Statement can accept parameters at runtime.
In case of the following example,what will be result of the code, if class Dog extends class
Animal: Dog d = new Dog();//syntax of upcasting System.out.println(d instanceof Animal);
False
Which of these is NOT the idea behind an Encapsulation?
It enables you to “program in the general” rather than “program in the specific”
What will be the output of the following Java code?public class Shape {
return 1;
Main( ) {
}}public class Square extends Shape {
public static void main(String[ ] args){
public int area( ){
public int area( ){
return 2;
Shape shape = new Shape( );
}}class
Square square = new Square( );
square = shape;
System.out.println(square.area( ));
}}
Select one:
a. Compilation Error ?
/////.
c. 3.
Which of these is FALSE about static members?
A memory for storing static members is allocated during the object creation
______ is a Java API that is used to connect and execute query to the database
Select one:
JDBC
There are two types of exceptions in java: checked and unchecked (runtime) exceptions:
True
What will be the output of the following Java code?public class Shape { public int area()
{ return 1;
}}public class Square extends Shape { public int area()
{ return 2; }}public class Rectangle extends
Shape { public int area()
{ return 3; }}class Main() {
public static void main(String[] args)
{
Shape shape = new Shape(); Square square = new Square(); Rectangle rect = new Rectangle(); rect =
(Rectangle)square; System.out.println(square.area()); }}
Select one:
Compilation failure
Which of these keywords is used to manually throw an exception?
throw
Which of the following is correct about Java 8 lambda expression?
Select one:
Both of the above.
What is not considered as a Design principle?
High cohesion
What is the correct sequence to create a database connection?i.Import JDBC packages.ii.
Establish the connection.iii. Define the connection URL.iv. Execute a query.v. Create a
statement object.vi. Close the resultset and statement objects.vii. Process the resultset.viii.
Close the connection.
i, iii, ii, v, iv, vii, vi, viii
What is TRUE about Interface?
All of the above
What are the major components of the JDBC?
DriverManager, Driver, Connection, Statement, and ResultSet
When a reference variable of a Parent class refers to the object of the Child class, then it is
known as
Upcasting
Which of the following contains only unimplemented methods?
Interface
What is used to execute parameterized query?
PreparedStatement interface
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
What type of inheritance does Java have? (single inheritance)
Block finally in exception handling executes: (Always)
In order to handle exceptions in java we use: (try{…} catch(…){…})
What can help to achieve multiple inheritance in Java? (Interfaces)
What is the benefit of using interface instead of abstract class in Java? (it is possible to
implement several interfaces in one class)
Non-static fields and methods can be called from static methods: (false)
Which of these is NOT an advantage of OOP? (less program size)
Which of these is a reference to the current object? (this)
Which of these is the main idea behind “Polymorphism”? (it enables you to “program in the
general” rather than “program in the specific”)
What kind of constructors exists in Java? (No argument and parameterized constructors)
Which of the following is false about encapsulation? (In encapsulation the methods of the class
will be hidden)
One class could have only one constructor: (false)
Which of the following is TRUE in Java? (one class can implement more than one interfaces)
To prevent any method from overriding, we declare the method as: (final)
Which of these is a reference to the parent class object? (super)
An inheritance is … : (the mechanism by which one class is allowed to inherit the features (fields
and methods) of another class)
Static fields and methods can be called from non-static methods: (True)
Which of these is NOT the idea behind an Encapsulation? (it enables you to “program in the
general” rather than “program in the specific”)
What is the reason to use try-catch block? (For exception handling)
The built-in base class in Java, which is used to handle all exceptions is: (Throwable)
Call to super() must be first statement in subclass constructor. What will happen if you don’t call
it explicitly? (the compiler would attempt to insert a call to the superclass’s default constructor)
Choose the correct type of polymorphism for: 1. Method overloading
2.Method overriding
(1. compile-time polymorphism and 2. Runtime polymorphism)
What allows you to save time during program development by basing new classes on existing
proven and debugged high-quality software? (Interface)
What is FALSE about a constructor? (A constructor is a public method of a class which can be
explicitly called using a class object)
What should a programmer do if the class partially implements the interface in Java? (Add
abstract keyword in the declaration of this class)
Which of this keyword must be used to inherit a class? (extends)
Which of the following is not the name of a Java primitive data type? (String)
Which of these is FALSE about static members? (A memory for storing static members is
allocated during the object creation)
What is protected access modifier? (It gives permission to access current member only from
subclasses or from the same package)
Which of these can be used only when an object of that class type has been created: (Non-static
members)
What is the advantage of Encapsulation? (All of the above)
Which of these types is non-primitive? (int[])
What is an object? (It is an instance of class)
Which OOP principle enables you to deal in generalities and let the execution-time environment
handle the specifics? (Polymorphism)
It is a mechanism of wrapping the data and code acting on the data together as a single unit:
(Encapsulation)
Choose the correct structure for exception handling: (try{…} catch(exception){…})
37. What is TRUE about private member variables? (Private member variables can be accessed
indirectly using their accessors and mutators)
38. What is the main difference of abstract class from the concrete class? (It is not allowed to
instantiate an object using an abstract class)
39. When subclass has its own implementation, different from superclass version it is called:
(method Overriding)
40. Find a definition of Casting in Java: (Casting is the process of converting one data type to
another)
What is the reason to use method overriding? It is used whenever subclass needs specific
implementation of superclass method [+]+++
What is FALSE about a constructor? A constructor is a public method of a class which can
be explicitly called using a class object[+]+++
What is an aggregation? It is a relationship between objects, where both the entries can
survive individually which means ending one entity will not effect the other entity [+]+++
What is an object? It is an instance of class[+]+++
What is FALSE about casting in Java? One subclass reference can be casted to absolutely
another subclass reference of the same direct superclass[+]+++
Find a definition of Casting in java Casting is the process of converting one data type to
another[+]+++
If A is a class.....B and C are interfaces, what is the proper signature for class A to extend
interfaces B and C? public class A implements B, C {} [+]+++
If data members are private, what can we do to access them from the class object? Create
public member functions to access those data members[+]+++
What is PROTECTED access modifier? It gives permission to access current member only
from subclasses or from the same package[+]+++
A class that cannot be subclassed is called a ________. Final class[+]+++
What is called using super() Super class`s no-argument constructor[+]+++
What is called using this() Current class`s no-argument constructor[+]+++
What is the reason to use try-catch block? For exception handling[+]+++
Which of the following is FALSE about abstract classes in Java A class can inherit from
multiple abstract classes [+]+++
What allows you to save time during program development by basing new classes on
existing proven and debugged high-quality software? inheritance [+]+++
It is a mechanism of wrapping the data and code acting on the data together as a single
unit Encapsulation[+]+++
An inheritance is ... the mechanism by which one class is allowed to inherit the features
(fields and methods) of another class. [+]+++
What is the main difference of an interface from abstract class? An interface contains only
abstract methods [+]+++
In the example code fragment shown below:public abstract class Test { // . . . more class
code No object of type Test can ever be created [+]+++
What is TRUE about private member variables? Private member variables can be accessed
indirectly using their accessors and mutators [+]+++
What is described in the following statement?_"A programmer using a method that you
have defined does not need to know the details of the code in the body of the
method"_Data hiding [+]+++
What is TRUE about objects` association? Aggreagation is when objects are using "has-a"
relationship, whereas, composition is when objects are using "is-part-of" relationship
[+]+++
Call to super() must be first statement in subclass constructor. What will happen if you don’t
call it explicitly? The compiler would attempt to insert a call to the superclass’s default
constructor [+]+++
How many errors in the code below? (write single integer
number)CLASS Hobbit EXTEND Actor {
100.0;
PRIVATE DOUBLE stealth;
PUBLIC VOID Hobbit()
{
stealth = MAX_STEALTH / 2.0;
{
THIS.stealth = stealth;
{
System._OUT_.print(stealth);
{
RETURN "hobbit";
}
PUBLIC STATIC constant DOUBLE MAX_STEALTH =
}
PUBLIC VOID setStealth(DOUBLE stealth)
PUBLIC VOID displayStatus()
}
PUBLIC toString()
} }4[+]+++
How many errors in the code below? (write single integer
number)CLASS Employee{
PRIVATE String name;
mployee(String name, FLOAT salary){
salary;
24;
}
THIS.name = Name;
PUBLIC FLOAT calcPay() {
PUBLIC E
THIS.salary =
RETURN salary /
}} CLASS Sales EXTENDS Employee{
otalSales;
PRIVATE FLOAT salary;
PRIVATE FLOAT commission;
PUBLIC Sales(String name, FLOAT salary){
PRIVATE FLOAT t
SUPER(name, salary);
}}
3[+]+++(difference in “PRIVATE FLOAT totalSales;” and “PRIVATE totalSales;”)
How many errors in the code below? (write single integer
number)PUBLIC Employee{
PRIVATE String name;
mployee(String name, FLOAT salary){
salary;
}
PRIVATE FLOAT salary;
THIS.name = Name;
PUBLIC FLOAT calcPay() {
PUBLIC E
THIS.salary =
RETURN salary /
24;
}} CLASS Sales EXTENDS Employee{
PRIVATE FLOAT commission;
es;
PUBLIC Sales(String name, FLOAT salary){
SUPER(name, salary);
(difference in “PRIVATE FLOAT totalSales;” and “PRIVATE totalSales;”)
This class cannot be used to instantiate objects Abstract class[+]+++
PRIVATE totalSal
} }2 [+]+++
In other words encapsulation is: Data hiding [+]+++
How do you call a group of related methods with empty bodies? interface[+]+++
What is the main difference of abstract class from the concrete class? It is not allowed to
instantiate an object using an abstract class[+]+++
When a reference variable of a Parent class refers to the object of the Child class, then it is
known as Upcasting[+]+++
[Quadrangle 2]Which of the following is a mistake from the given code? (IT IS
RECOMMENDED TO READ ANSWER OPTIONS FIRST) Class Quadrangle must be
abstract[+]+++
[Quadrangle4]Which of the following is a mistake from the given code? (IT IS
RECOMMENDED TO READ ANSWER OPTIONS FIRST) Class Rectangle must provide a
constructor that explicitly calls its parent`s (Quadrangle`s) parametrized constructor[+]+++
What is a composition? It is a relationship between objects where the composed object
cannot exist without the other entity[+]+++
A private member of a class is visible to: members of same class [+]+++
What do we use to define the state of an object? Field[+]+++
Say that there are three classes: Computer, AppleComputer, and IBMComputer. What are
the likely relationships between these classes? Computer is the superclass, AppleComputer
and IBMComputer are subclasses of Computer. [+]+++
A class can have only one constructor False [+]+++
public static void main(String args[]) (which part of the code above responsible for method
being taken as a starting point of an application by JVM?) Main [+]+++
A class can have more than one constructor with different signature True[+]+++
public static void main(String args[]) (which part of the code above responsible for method
being accessible by any class?) public[+]+++
Non-static fields and methods can be called from static methods False [+]+++
How many objects of a given class can there be in a program? As many as the program
needs. [+]+++
Java is a/an ______ Object-oriented programming language[+]+++
Constructor can return a value False[+]+++
In Object-Oriented Programming, public, private & protected are: Access Modifiers[+]+++
Say that a particular item of data does not use a primitive data type. What must it be? An
object. [+]+++
public static void main(String args[]) (which part of the code above responsible for method
not returning any value?) void [+]+++
Non-static fields and methods cannot be called from static methods True[+]+++
Static fields and methods can be called from non-static methods True [+]+++
What are the advantages of OOP? Reusability[+]+++
Static fields and methods defined in a class can be used only when an object of that class
type has been created False [+]+++
What do we call a simple function that is called using reference variable? Method [+]+++
Inheritance is used when the relationship between two classes _______ relationship. isa[+]+++
What are the relationships in the following sentences? A computer owns a CPU. A computer
has a user. composition, aggregation [+]+++
Encapsulation is a mechanism of wrapping _____ and code acting on _____ together as a
single unit. Fill the missing part. variables, methods[+]+++
A class Animal has a subclass Mammal. Which of the following is true: Mammal can have no
other parent than Animal. [+]+++
What do we use to define the behavior of an object? Method [+]+++
public static void main(String args[]) (which part of the code above responsible for method
or variable not being an instance related but class related?) static[+]+++
Which of these class is superclass of every class in Java? Object class[+]+++
A class should have only one reason to change is definition of which principle? SRP
Ability to change behaviour of the class without making change in class itself is property of
which design principle? OCP
Class Circle is subclass of Shape, class Shape has method isFilled() that checks if shape is
filled or not. If you override method isFilled() in class Circle and you will throw exception
when radius of the circle is less than or equal to 0 which design principle you are breaking?
LSP
Class Employee has method salary(). If I create another class EmployeeSalaryUpdate that
extends from Employee and will override salary() method to add bonuses for overtime work
which principle I will follow? OCP
Consider some class HashMap<K,V>, what is correct way to instantiate object of this class?
HashMap<Integer,String> map = new
HashMap<Integer,String>();
Entities should be open for extension, but closed to modifications is definition of which
principle?: OCP
Fill the gaps: Block finally is executed ______ try-catch block ______ before, only when there is
no exception
Generic types can be placeholders for: Reference data types
How we call problems that rises when we are running programs? Exceptions
How you can display the exception message to the console? In catch block using instance
of Exception class print the instance in the body of the block
In following lambda expression: "Subtraction sub1 = (x, y) -> x-y;" how we can trigger it?
Assume interface Subtraction has single method "int subtract(int f, int z)".
sub1.subtract(10,5);
In JDBC you need to use ResultSet... to get all values from a table and store them
In main method: "public static void main(String[] args)", what is return type? void
Are ResultSets updateable? Yes, but only if we indicate a concurrency strategy when
executing the statement, and if the driver and database support this option.
Can we keep other statements in between try, catch and finally blocks? No
Can we override a super class method which is throwing an unchecked exception with
checked exception in the sub class? No
Can we throw an exception manually? Yes
Can we write only try blocks without catch blocks? Yes, but it is required to add finally block
Does finally block get executed If either try or catch blocks are returning the control? Yes
Exception generated in try block is caught in ______ block catch
Exceptions are mainly caused by the application itself. For example, NullPointerException
occurs when an application tries to access null object. True
Exceptions are mainly caused by the environment in which an application is running. For
example, OutOfMemoryException happens when Java runs out of memory False
JDBC is a Java API that is used to connect and execute query to the database True
Parameterized queries can be executed by? PreparedStatement
Parameterized queries in JDBC can be executed by? PreparedStatement
Select the package in which JDBC classes are defined? sql
Select the packages in which JDBC classes are defined? sql and javax.sql
It is possible to invoke methods at runtime irrespective of the access specifier
(private/public) with the use of some API: True
The Java feature, "write once, run anywhere", is termed as Platform independent
The statement: "Reflection exists only in java programming language" is: True
Dependency Inversion Principle stands that: Code should depend on abstraction
Interface Segregation Principle stands for: Object shouldn't be forced to implement an
interface that it doesn't use
L in SOLID stands for: . Liskov's substitution principle
In case of the following example, the result of the code will be:Dog d =
null;System.out.println(d instanceof Dog); False
What will be the output of the following Java code snippet?
public class Shape{
return 1;
public int area( ){
}}
public class Rectangle extends Shape {
public int area( ){
return 3;
}}
class Main( ){
public static void main(String[ ] args){
Shape shape = new Shape( );
Rectangle rect = new Rectangle( );
shape = rect;
System.out.println(shape.area( ));
}} 3
What will be the output of the following Java code?
public class Shape { public int area()
{ return 1; }}
public class Square extends Shape {
public int area()
{ return 2; }}
public class Rectangle extends Shape {
public int area()
{ return 3; }}
class Main() {
public static void main(String[] args)
{
Shape shape = new Shape();
Square square = new Square();
Rectangle rect = new Rectangle();
rect = (Rectangle)square;
System.out.println(square.area());
}} Compilation Error
What is not true for JDBC: It can be found in special java.postgresql package
Which of these keywords is used to manually throw an exception? Throw
Which of these keywords must be used to monitor for exceptions? Try
_____ is a Java API that is used to connect and execute query to the database: JDBC
Which of the following holds data retrieved from a database after you execute an SQL query
using Statement…. : ResultSet
Which of the following is correct about Java 8 lambda expression? Both of the above
Which of the following is not an exception? ErrorException
Using which return type in methods you can return several values? Array List
Which symbol helps to dynamically pass parameters in PreparedStatement? Question mark
Which of the following method is used to perform DML (Data Manipulation Language)
statements in JDBC? executeUpdate()
Which methods you can use to process the results of Result Set: getString, getInt, next
Which of the design principles is best described by following statement: You need to
develop programs in such a manner that program be autonomous and connected through
abstraction (interfaces).: DIP
Which of the following are checked exceptions? NullPointerException
[Quadrangle4] Which of the following is a mistake from the given code? (IT IS
RECOMMENDED TO READ ANSWER OPTIONS FIRST): Class Rectangle must provide a
constructor that explicitly calls its parent’s (Quadrangle’s) parametrized constructor
Which of the following is not correct property of exceptions: Exception handling does not
help to terminate program gracefully
Which principle is broken in the following case: In class “Order you create methods to save
order, to place the order in database and notification confirming the order: SRP
What does Liskov substitution principle specify? parent class can be substituted by child
class
Using what kind of object you can execute sql commands? Statement
What kind of exception appears when compiler will try to divide by 0? Arithmetic
Which of the following is not considered as good practice: name methods using camel style
Which of these keywords is not a part of exception handling? Thrown
Which of the following is false regrding lambda expressions: it is not possible to return
lambda expressions from methods
Which of these classes are the direct subclasses of the Throwable class? Error and Exception
class
There are two types of exceptions in java: checked and unchecked (runtime) exceptions:
True
Which of the following is correct about ResultSet class of JDBC? All of the above.
What will be the correct option of the following Java code snippet? interface ICust {...} class
RegularCustomer implements ICust {...} class OneTimeCustomer implements ICust {...}
OneTimeCustomer can be replaced with RegularCustomer
What is not a property of Exception Handling Terminate a program when exception occurs
[Quadrangle 2]Which of the following is a mistake from the given code? (IT IS
RECOMMENDED TO READ ANSWER OPTIONS FIRST)
What is true for lambda expression? Lambda can be created using list of parameters, arrow
sign, and body of the method
Download
Study collections