final oop

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Java supports only single inheritance, in which each class is derived from exactly one direct superclass. TRUE or FALSE?

TRUE

Which methods you can use to process the results of Result Set

getString, getInt, next

Which of the following principles asks us to implement Is-A relationship carefully?

liskov substitution principle

Which of these access specifiers must be used for main() method?

public

public static void main(String args[]) (which part of the code above responsible for method being accessible by any class?)

public

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

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

Which of these is a reference to the parent class object?

super

What can be accessed by members of the superclass, of its subclasses and other classes in the same package?

superclass's protected members

What method is implemented in Cosmic Superclass?

toString()

In order to handle exceptions in java we use:

try { ... } catch(exception) { ... }

What are the advantages of OOP?

Reusability, Efficiency, Extensibility, Refactoring

Using what kind of object you can execute sql commands?

Statement

What is false regarding statements in JDBC?

Statement can accept parameters at runtime

What is the correct option to create a statement?

Statement stmt = connection.createStatement();

Which among the following best describes constructor overloading?

Defining more than one constructor in single class with different signature

Which of these keywords must be used to monitor for exceptions?

Try

What's the extension for a compiled Java file?

.class

What is an advantage of Encapsulation?

1. An outside class can not access the data members of that class. 2. With encapsulation we can make the data as read-only or write-only as we require it to be. 3. It allows the programmer to use the existing code again and again in an effective way

Choose correct type of polymorphism for: Method overloading Method overriding

1. compile-time polymorphism and 2. runtime polymorphism

Find a definition of Casting in java

Casting is the process of converting one data type to another

Which of these is FALSE about static members?

A memory for storing static members is allocated during the object creation

Which one(s) is true about Single Responsibility Principle?

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

Which of the following is about Single-responsibility principle?

A class should only have a single responsibility

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

This class cannot be used to instantiate objects

Abstract class

How do you call a group of related methods with empty bodies?

Abstraction

What are public, private & protected in OOP?

Access Modifiers

A public method that reads and returns data from one or more private instance variables

Accessor method

What should a programmer do if the class partially implements the interface in JAVA?

Add abstract keyword in the declaraion of this class

Default constructor initializes all data members as ___________

All numeric member with zero and strings to null

Block finally in exception handling executes:

Always

What is the main difference of an interface from abstract class?

An interface contains only abstract methods

Say that a particular item of data does not use a primitive data type. What must it be?

An object

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

What kind of exception appears when compiler will try to divide by 0?

Arithmetic

Using which return type in methods you can return several values?

Array List

How many objects of a given class can there be in a program?

As many as the program needs.

The relation between Car and Owner or BankAccount and Customer is example for

Association

Which of the following best defines a class?

Blueprint of an object

Which of the following can be static?

Class

Which of these keywords is used to make a class?

Class

Dependency Inversion Principle stands that

Code should depend on abstraction

The principle of component cohesion is _____

Common Closure Principle, Common Reuse Principle, Reuse/Release Equivalence Principle

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.

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

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

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

In other words encapsulation is:

Data hiding

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

Which one(s) is true about the Dependency Inversion Principle?

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?

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

Which class is used to get the connection to database?

DriverManager

What are the major components of the JDBC?

DriverManager, Driver, Connection, Statement, and ResultSet

It is a mechanism of wrapping the data and code acting on the data together as a single unit

Encapsulation

Which OOPS concept means exposing only necessary information to the calling functions?

Encapsulation

Which of these classes are the direct subclasses of the Throwable class?

Error and Exception class

Which of the following is not an exception?

ErrorException

Which one(s) is true about Liskov Substitution Principle?

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

How we call problems that rises when we are running programs?

Exceptions

A class can have only one constructor

False

Constructor can return a value

False

Exceptions are mainly caused by the environment in which an application is running. For example, OutOfMemoryException happens when Java runs out of memory

False

Generics represent an anonymous method—that is, a method without a name.

False

One class could have only one constructor

False

The diamond problem could occur when we deal with single inheritance

False

What do we use to define the state of an object?

Field

A class that cannot be subclassed is called a ________.

Final class

What is the reason to use try-catch block?

For exception handling

Which one(s) is true about the Common Closure Principle?

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

Which oops concept is used as reuse mechanism?

Inheritance

Consider some class HashMap, what is correct way to instantiate object of this class?

HashMap<Integer,String> map = new HashMap<Integer,String>();

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

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

Which of the following is false about encapsulation?

In encapsulation the methods of the class will be hidden

What allows you to save time during development by basing new classes on existing proven and debugged high-quality software?

Inheritance

What allows you to save time during program development by basing new classes on existing proven and debugged high-quality software?

Interface

Which of the following contains only unimplemented methods?

Interface

What can help to achieve multiple inheritance in Java?

Interfaces

What is protected access modifier?

It gives permission to access current member only from subclasses or from the same package

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 the main difference of abstract class from the concrete class?

It is not allowed to instantiate an object using an abstract class

What is the reason to use method overriding?

It is used whenever subclass needs specific implementation of superclass method

. ______ is a Java API that is used to connect and execute query to the database

JDBC

What is JDBC?

Java Database Connectivity

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

What is true for lambda expression?

Lambda can be created using list of parameters, arrow sign, and body of the method

Which of these is NOT an advantage of OOP?

Less program size

Which of these is NOT an advantage of OOP?

Less program size.

L in SOLID stands for

Liskov's substitution principle

Which of these can be used only when an object of that class type has been created

Nonstatic members

Which one(s) is true about Interface Segregation Principle?

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

A class Animal has a subclass Mammal. Which of the following is true:

Mammal can have no other parent than Animal.

Which of the following is about Interface segregation principle?

Many client-specific interfaces are better than one general-purpose interface.

What do we use to define the behavior of an object?

Method

When subclass has its own implementation, different from superclass version it is called _____

Method Overriding

What kind of programming languages is Java?

Object-Oriented Programming Language

Java is a/an

Object-oriented language

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

What kind of constructors exist in Java?

No argument and parameterized constructors

In the example code fragment shown below:public abstract class Test { // . . . more class code

No object of type Test can ever be created

Which of the following are checked exceptions?

NullPointerException

What is output of the following program if input is t 0?

NumberFormatException!

Ability to change behaviour of the class without making change in class itself is property of which design principle?

OCP

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

Entities should be open for extension, but closed to modifications is definition of which principle?

OCP

Which class is called as "Cosmic superclass"

Object

Which of these class in superclass of every class in Java?

Object class

Interface Segregation Principle stands for

Object shouldn't be forced to implement an interface that it doesn't use

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.

Which of the following is True in JAVA?

One class can implement more than one interface

Which of the following is TRUE in JAVA?

One class can implement more than one interfaces

What is FALSE about casting in Java?

One subclass reference can be casted to absolutely another subclass reference of the same direct superclass

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

The Java feature, "write once, run anywhere", is termed as

Platform independent

Which OOP principle enables you to deal in generalities and let the execution-time environment handle the specifics?

Polymorphism

Parameterized queries can be executed by?

PreparedStatement

Parameterized queries in JDBC can be executed by?

PreparedStatement

What is used to execute parameterized query?

PreparedStatement interface

What is TRUE about private member variables?

Private member variables can be accessed indirectly using their accessors and mutators

Which of the following statements is correct?

Public method is accessible to all other classes in the hierarchy

Which symbol helps to dynamically pass parameters in PreparedStatement?

Question mark

Generic types can be placeholders for:

Reference data types

Which of the following holds data retrieved from a database after you execute an SQL query using Statement...

ResultSet

SOLID term was introduces by

Robert Martin

A class should have only one reason to change is definition of which principle

SRP

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

Which of the following is not the name of a Java primitive data type?

String

Which class is a class that inherits a method or methods from a superclass?

Sub class

What is called using super()

Super class's no-argument constructor

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

Which one(s) is true about the Reuse/Release Equivalence Principle

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 of these keywords is not a part of exception handling?

Thrown

A class can inherit instance variables and methods from a more abstract superclass. Select one: a. True b. False

True

Encapsulation is used to control variable assignment?

True

Exceptions are mainly caused by the application itself. For example, NullPointerException occurs when an application tries to access null object.

True

Interfaces also may contain public default methods with concrete default implementations

True

Interfaces specify how operations are performed when an implementing class does not override the methods

True

It is possible to invoke methods at runtime irrespective of the access specifier (private/public) with the use of some API

True

JDBC is a Java API that is used to connect and execute query to the database

True

Non-static fields and methods cannot be called from static methods

True

Static Methods in Interface are those methods, which are defined in the interface with the keyword static

True

Static methods contain the complete definition of the function

True

The statement: "Reflection exists only in java programming language" is

True

There are two types of exceptions in java: checked and unchecked (runtime) exceptions

True

When a reference variable of a Parent class refers to the object of the Child class, then it is known as

Upcasting

Can we throw an exception manually?

Yes

Does finally block get executed If either try or catch blocks are returning the control?

Yes

Can we write only try blocks without catch blocks?

Yes, but it is required to add finally block

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.

is it possible to return lambda expressions from methods?

Yes, it is possible to return lambda expressions from methods in Java.

Which one(s) is true about Open/Closed Principle?

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

An interface cannot have an child. Select one: a. False b. True

a. False. In Java, an interface can have child interfaces that extend it. A child interface can inherit all the abstract methods and constants of its parent interface, and can also add its own methods and constants.

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

a. Number of arguments and type of arguments

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

b. Constructors are always user defined

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

b. Static fields and methods cannot be called from non-static methods

Block finally is executed ______ try-catch block ______

before, only when there is no exception

What is it called where child object gets killed if parent object is killed? Select one: a. Aggregation b. Association c. Composition d. Encapsulation

c. Composition

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

c. Demo(Demo1 demo){...}

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

c. Yes

Exception generated in try block is caught in ______ block.

catch

Which of these is correct way of inheriting class A by class B?

class B extends A {}

Which is correct syntax for creating an object of Class in Java?

classname objectname = new classname();

What are the relationships in the following sentences? A computer owns a CPU. A computer has a user

composition, aggregation

What is SOLID?

design patterns

What is Rigidity?

every change affects many other parts

Which of the following method is used to perform DML (Data Manipulation Language) statements in JDBC?

executeUpdate()

Which of this keyword must be used to inherit a class?

extends

To prevent any method from overriding, we declare the method as

final

___ method cannot be overridden by a subclass

final

Which of these types is non-primitive?

int[]

How do you call a group of related methods with empty bodies?

interface

Inheritance is used when the relationship between two classes _____

is-a

Which of these is the main idea behind "Polymorphism"?

it enables you to "program in the general" rather than "program in the specific"

Which is the benefit of using interface instead of abstract class in Java?

it is possible to implement several interfaces in one class

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

Which method can be defined only once in a program?

main method

What is a direct superclass of monkey in the following scheme? animal - mammal - monkey - gorilla

mammal

A private member of a class is visible to:

members of same class

When the subclass method is intended as a replacement of the superclass method

overriding

What does Liskov substitution principle specify?

parent class can be substituted by child class

What type of inheritance does Java have?

single inheritance

What does "S" in the SOLID stand for?

single responsibility principle

Select the package in which JDBC classes are defined?

sql

Select the packages in which JDBC classes are defined?

sql and javax.sql

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

An inheritance is ...

the mechanism by which one class is allowed to inherit the features (fields and methods) of another class.

What is Fragility?

things break in unrelated places

Which of these is a reference to the current object?

this

Which of these keywords is used to manually throw an exception?

throw

The built-in base in Java, which is used to handle all exceptions is

throwable

In JDBC you need to use ResultSet...

to get all values from a table and store them

. In order to use encapsulation inside a class, method and variable must be:

variable-private , method-public

Encapsulation is a mechanism of wrapping _____ and code acting on _____ together as a single unit. Fill the missing part.

variables, methods

In main method: "public static void main(String[] args)", what is return type?

void

What is the return type of a method that does not return any value?

void

Which of the following is true about Lambda expressions?

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


Ensembles d'études connexes

VGCA-175-A chapter 19: Professional Management and the Small Business

View Set

Anatomy > MD > Upper Limb (To finish)

View Set

Biology chapter 24 - multiple choice

View Set

Perspectives Upper-Intermediate Unit 1

View Set

Micro Chapter 14 - Classifying infectious diseases

View Set