CMPS 280 Flashcards

1
Q

What is inheritance?

A

States and behaviors can be passed down.

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

Give an example of inheritance.

A

There can be a superclass called Shape. You can create a square, circle, and triangle class that inherits from shape. So now square, circle, and triangle can use all of the methods and attributes that the shape class uses.

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

In inheritance, child classes can reference the parent class, but…

A

parent classes can’t reference the child classes.

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

How do you perform inheritance?

A

Use the extends keyword. public class Shape{ } public class Square extends Shape{ } public class Triangle extends Shape{ } public class Circle extends Shape{ }

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

What is an interface?

A

An interface provides a contract for functionality. If another class inherits from an interface, that class is forced to use all of the methods that are placed inside of an interface.

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

What is polymorphism?

A

Polymorphism is the capability of a method to do different things based on the object that it is acting upon.

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

Why do we use polymorphism?

A

We use polymorphism if we have classes that would use the same methods but with different actions

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

Give an example of polymorphism using method overloading.

A

public class Dog extends Animal

{

public void makeSound() {

System.out.println(“woof!”);

}

public void makeSound(boolean isInjured)

{

System.out.println(“whimper”);

}

}

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

Give an example of polymorphism using method overriding

A

public class Animal

{

//properties

public virtual void makeSound() {

}

}

public class Dog : Animal {

//properties

public void override makeSound() {

Console.WriteLine(“woof”);

}

}

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

What is an accessor and mutator?

A

An accessor is a fancy word for a getter method. An accessor returns a class’s variable or its value. A mutator is a fancy word for setter. A mutator sets a class’s variable or its value.

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

Give an example of an accessor and mutator.

A

public String getName() {

return mName;

}

public void setName( String name ) {

mName = name;

}

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

What is the “this” keyword?

A

this is an alias or a name for the current instance inside the instance.

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

What is an abstract class?

A

An abstract class has no objects, and can contain abstract methods (but doesn’t have to contain abstract methods)

Shape s = new Circle();

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

What is an abstract method?

A

-

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