Chapter 4 Java

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

True or False: Every Java class has at least 1 constructor

True: if you don't define one the compiler gives a no-args constructor that initializes all instance variables to default values (0 for #s, null for objects, false for boolean)

True or False: A class may have more than one constructor.

True; A class may have many different constructors.

True or False: The programmer gives names to objects in his program.

True; A programmer may give his objects any name.

What are accessor methods/accessors/getters?

public methods that return the values of an object's private fields so that an object of a different class can access those values

Several compiled java classes may be collected in one ________

.jar file

What are three benefits of encapsulation?

1. The fields of a class can be made read-only or write-only. 2. A class can have total control over what is stored in its field. 3. The users of a class do not know how the class stores its data. A class can change the data type of a field and users of the class do not need to change any of their code.

What is inheritance?

Can create a new class by extending an existing one.

True or False: A Java program is allowed to create only one object of each class.

False; An infinite number of objects may exist.

True or False: The import statement tells the compiler which other classes use this class.

False; It tells the compiler where it can find classes used by this class.

True or False: Every class has a method called "main".

False; No, you can have classes with different methods.

True or False: A subclass inherits all those constructors of its superclass that are not defined explicitly in the subclass.

False; constructors aren't inherited.

In Java every class extends the library class _______ by default.

Object

True or False: Fields of a class are usually declared "private".

True

A subclass does not inherit ________

constructors

What's a CRC card?

index card that gives basic, informal description of a class: name, key responsibilities of objects, collaborators (other classes this class depends on)

If void is in a method's header it means that ________

the method does not return a value Ex: main

What does it mean when a method is declared static?

That method belongs to a class as a whole, not to any particular object of that class.

What is the IS-A relationship between objects?

an object of a subclass IS-A object of its superclass

What are setters/modifiers?

methods that set the values of private fields

A subclass inherits all the ______ & _______ of its superclass.

methods, fields

True or False: The name of a class in Java must be the same as the name of its source file. (excluding the extension ".java")

True; A class cannot have a different name than the source file.

True or False: A Java program may have as many classes as necessary.

True; You can have an infinite number of classes in a Java program.

True or False: An object has to be created before it can be used.

True; You can't use something that doesn't exist.

True or False: The names of classes are case-sensitive.

True; You must use the correct case when naming classes.

True or False: A subclass inherits all the fields and public methods of its superclass.

True; a subclass does inherit all the fields and public methods.


Set pelajaran terkait

AP Computer Science Principles S1 Final Exam

View Set

FoE9 wbp.20 match the word with its definition

View Set

ECON 101 Final Material (UMICH - Wolfers)

View Set

Official Cert Guide CCNA 200-301 Part 2

View Set