Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Quiz 1

Q1. A is an instance of class employee that contains information about employee

Wassim.

B is another instance of class employee, containing the same information about the same employee Wassim.

What will A == B return?

 

c)   Java will print "The two variables are equal."

d)  Error, Java will not know how to compare instances of a user defined class

Q2. Public int sup_guys(int a, int b)

{}

//main method

Int c = 1;

Int d=2;

Sup_guys(c, d)

What are the actual parameters in this example?

a)   a and c

b)  c and d

c)   b and d

d)  a and b

Q3. A variable assigned to an instance of a class created by the user is a primitive data type

a)   True

b)  False

Q4. In Java, a constructor method must be explicitly called to instantiate an instance of a class

a)   True

b)  False

Q5. Java allocated a fixed size in memory for primitive data types.

a)

b)

Quiz 2

Q1. What is the difference between an instance of a class and an object of type class?

a)   An instance of a class can't be edited, while an object can be edited

b)  You can create many instances of a class, but only one object of a class can be created

c)   They refer to the same thing

d)  In general, an object of a class runs faster than an instance of a class

Q2. A variable declared private in a class:

a)   Can only be of primitive type

b)  Can be accessed through any instance of the class.

c)   Can't be changed after it has been set an initial value

d)  Can only be accessed by methods defined in the same class.

Q3. By default, a class is visible only to the other classes of the same package.

a)   True

b)  False

Q4. What is the difference between a class variable and an instance variable?

a)   Class variables are shared across all instances of a class, while instance variables are specific to every instance of a class

b)  Class variables can only be accessed if the class is declared public, while instance variables could be accessed regardless of whether or not the class is declared        public

c)   They have the same functionality

d)  Instance variables occupy less space in memory than class variables

Q5. Maintainability and coupling are inversely proportional.

a)   True

b)  False

Quiz 3

Q1. When a class inherits another class:

a)    It inherits all method definitions

b)   It inherits all class variables

c)    It can override methods defined in the parent class

d)   A and B

e)    All of the above

f)    None of the above

Q2. If a variable in a class is declared as private, it cannot be accessed by the children

 

b)

Q3. If a variable in a class is declared as protected, it cannot be accessed by the children classes

True

b)

Q4. If a method is declared as final in a parent class, children classes would still be able to override it.

a)    True

b)   False

Q5. Abstract classes cannot have any concrete function definitions. It only defines what functions must be implemented in any children classes, but it can't have a     concrete function definition on its own.

a)

b)

Quiz 4

Q1. What does the super keyword do?

a)    It has super powers - How should I know?

b)   It calls the constructor of the parent class

c)    It must be called in the very first line of a constructor

d)   It prevents the overriding of any class methods

e)    B and C

f)    None of the above

Q2. Polymorphism allows us to have different implementations of a function with the same name, depending on the type of class it is being called from.

a)    True

b)   False

Q3. How many direct super classes can a class have?

a)    2

b)   Indefinite

c)    1

d)   0

Q4. If you have the following class:

public class Dog extends Animal{...}

And the following method:

public int sup(Animal x){...}

What would happen if you call sup on an instance of class Dog?

a)    Java will throw an error (incompatible type)

b)   Function sup will be called and will operate normally

c)    Java will throw an error (out of memory)

d)   None of the above