Classes and Objects 3 Flashcards

1
Q

What is the definition of package?

A

Allows to group classes and interfaces into bundles, that can then be handled together using an accepted naming convention

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why would you group classes into packages?

A
  • Allows reuse, rather than rewriting classes, you can use existing classes by importing them
  • Prevents naming conflicts
    • classes with the same name can be used in a program, uniquely identifying them by specifying the package they belong to
  • Allows access control
  • Another level of encapsulation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to create packages?

A

package <directory_name_1>.<directory_name_2>;</directory_name_2></directory_name_1>

This implies that the class in directory_2, which is a sub-directory of directory_1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to use java packages?

A

To use classes in a package, the import statement, which can take one of the following forms must be used:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the definition of default package?

A

All the classes in the current directory belong to an unnamed package called the default package - no package statement is needed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the definition of Information Hiding?

A

Ability to “hide” the details of a class from the outside world

Referred to as Visibility Control

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the definition of access control?

A

Preventing an outside class from manipulating the properties of another class in undesired ways

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why do we use information hiding?

A
  • Allows to safely seal data within the capsule of the class
  • Prevents programmers from relying on details of class implementation
  • Helps in protecting against accidental or wrong usage
  • Keeps code elegant and clean (easier to maintain)
  • Enables to provide access to the object through a clean interface
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the definition of visibility modifiers?

A

a list of keywords that are used to hide information

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the definition of public?

A

Keyword when applied to a class, method or attribute makes it available/visible everywhere (within the class and outside the class)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the definition of private?

A

Keyword when applied to a method or attribute of a class, makes them only visible within that class.
- Private methods and attributes are not visible within subclasses and are not inherited

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the definition of protected?

A

Keyword when applied to a method or attribute of a class, makes them only visible within that class, subclasses and also within all classes that are in the same package as that class. They are also visible to subclasses in other packages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the definition of mutable?

A

A class that contains public mutator methods or other public methods that can change the instance variables is called a mutable class, and its objects are called mutable objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the definition of immutable?

A

A class that contains no methods (other than constructors) that change any of the instance variables is called an immutable class, and its objects are called immutable objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the definition of delegation?

A

When a class delegates its responsibilities to other classes?

This is an Association relationship between the classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the definition of wrapper?

A

A class that gives extra functionality to primitives like int, and lets them behave like objects

17
Q

What is the definition of primitive?

A

A unit of information that contains only data, and has no attributes or methods

18
Q

What does wrapper classes do?

A
  • Allows primitive data types to be “packaged” or “boxed” into object
  • Allows primitives to “pretend” that they are classes
  • Provides extra functionality
19
Q

What methods does the Integer Class provide?

A
  • Reverse: Integer.reverse(10)
  • Rotate Left: Integer.rotateLeft(10, 2)
  • Signum: Integer.signum(-10)
  • Parsing Integer.parseInt(”10”)
20
Q

What is the definition of parsing?

A

Processing one data type into another