Midterm flash cards set

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/9

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

10 Terms

1
New cards

Explain the purpose and advantages of using enums in Java. Provide an example scenario where using enums would be beneficial.

Enums provide a type-safe way to represent fixed sets of constants. Enums ensure that only valid values can be assigned to a variable. For example, in an enum defined for days of the week, only the predefined days (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday) are allowed, which can help reduce bugs.

2
New cards

What is a static field? Explain how it is different from an instance field.

In Java, a static field is a field that belongs to the class itself, rather than to any specific instance of the class. This means that there is only one copy of the static field shared across all instances of that class. In contrast, an instance field belongs to individual objects of the class, meaning each object has its own copy of the instance field.

3
New cards

What is the purpose of access modifiers (e.g., public, private) in a class, and how do they impact class members?

In Java, access modifiers are keywords used to define the accessibility of classes, methods, constructors, and variables. They control how and where these members can be accessed. Public access modifiers allow members declared with the public keyword to be accessed from anywhere whether inside or outside the class. Private access modifiers allow members declared with the private keyword to only be accessed from inside the class.

4
New cards

Define the concept of aggregation in Java and explain its role in object-oriented programming.

In Java, aggregation is a concept used in object-oriented programming to represent a "has-a" relationship between objects. Aggregation occurs when an instance of a class is a field in another class.

5
New cards

Describe the purpose of constructors in Java classes.

In Java, constructors are special methods that are used to initialize objects when a class is instantiated by assigning values to its fields or any other setup required.

6
New cards

Discuss the use of the 'this' keyword in Java. How is it used to refer to instance variables and constructors within a class?

The ‘this’ reference is simply a name that an object can use to refer to itself. The ‘this’ reference can be used to overcome shadowing and allow a parameter to have the same name as an shadowed instance variable inside of a constructor.

7
New cards

What is the difference between a deep copy and a reference copy?

A reference copy is simply copying the address of an object into another reference variable. But a deep copy involves creating a new instance of the class and copying the values from one object into the new object.

8
New cards

What is the significance of the Object class in Java, and how does it relate to inheritance?

In Java, the Object class is the root of all other classes. This means that every class in Java inherits from the Object class. Because of this, the Object class offers a set of core methods that are inherited by every class in the Java programming language.

9
New cards

Describe the concept of method signature in Java. What does it include, and how does it determine method overloading?

In Java, a method signature is the combination of a method's name and its parameter list (types and order of parameters). In method overloading, it allows a class to have more than one method with the same name as long as their signatures are different.

10
New cards

Explain what happens when a constructor was never defined.

In Java, if a class does not explicitly define a constructor, the Java compiler automatically provides a default constructor. This is often referred to as the no-argument constructor, and it initializes the object with default values for its fields.