Java Quiz

Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Started on Sunday, 10 May 2020, 5:53 AM


State Finished
Completed on Sunday, 10 May 2020, 6:39 AM
Time taken 45 mins 32 secs
Grade 50 out of 60 (83%)

Question 1
Complete

Mark 1 out of 1

Which of these is not abstract?

Send us a message
Select one:
a. Thread
b. None of the Mentioned
c. List

d. AbstractList

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 1/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 2
Complete
Mark 1 out of 1

Does Java support multiple level inheritance?

Select one:
a. False
b. True

Question 3
Complete

Send us a message
Mark 0 out of 1

What is the output of the following JavaFX program?



Select one:
a. launch application. start method is invoked. Test constructor is invoked.
b. Test constructor is invoked. start method is invoked.
c. launch application. Test constructor is invoked. start method is invoked.
d. launch application. start method is invoked.
e. start method is invoked. Test constructor is invoked.

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 2/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 4
Complete
Mark 1 out of 1

You can assign ________ to a variable of Object[] type.

Select one or more:


a. new java.util.Date[100]
b. new int[100]
c. new String[100]
d. new char[100]
e. new double[100]

Send us a message
Question 5
Complete
Mark 1 out of 1

Which of the following statements are true?

Select one or more:


a. If a method overloads another method, these two methods must have the same signature.
b. A method in a subclass can overload a method in the superclass.
c. If a method overrides another method, these two methods must have the same signature.
d. A method can be overloaded in the same class.
e. A method can be overridden in the same class.

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 3/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 6
Complete
Mark 1 out of 1

Which method overrides the default behavior for the JFrame to be positioned in the upper-left corner of the computer screen’s desktop?

Select one:
a. title()
b. setBounds()
c. isResizable()
d. setSize()

Send us a message

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 4/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 7
Complete
Mark 1 out of 1

The GeometricObject and Circle classes are de ned in this chapter. Analyze the following code.

Select one or more:


a. To enable a Circle object to be cloned, the Circle class has to override the clone() method and implement the java.lang.Cloneable
interface.
b. The program has a compile error because the clone() method is protected in the Object class.
c. After you override the clone() method and make it public in the Circle class, the problem can compile and run just ne, but y is null if
Circle does not implement the Cloneable interface.

Send us a message
d. If GeometricObject implements Cloneable and Circle overrides the clone() method, the clone() method will work ne to clone Circle
objects.

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 5/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 8
Complete
Mark 1 out of 1

Suppose A is an interface, B is a concrete class with a default constructor that implements A. Which of the following is correct?

Select one or more:


a. B b = new A();
b. A a = new A();
c. B b = new B();
d. A a = new B();

Send us a message
Question 9
Complete
Mark 1 out of 1


You can use the keyword _______ within a method in a derived class to access an overridden method in a base class.

Select one:
a. this
b. sub
c. protected
d. super

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 6/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 10
Complete
Mark 1 out of 1

What is the output of this program?


class A
{
public int i;
protected int j;
}
class B extends A
{
int j;
void display()
{
super.j = 3;
System.out.println(i + " " + j);
}

Send us a message
}
class Output
{
public static void main(String args[])


{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}

Select one:
a. 1 2
b. 3 1
c. 1 3
d. 2 1

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 7/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 11
Complete
Mark 0 out of 1

Instead of using the automatic toString() method with your classes, it is usually more useful to write your own ____ version of the toString()
method that displays some or all of the data eld values for the object with which you use it.

Select one:
a. overridden
b. static
c. protected
d. overloaded

Send us a message
Question 12
Complete
Mark 1 out of 1

An interface cannot extend more than one interface.

Select one:
a. true
b. false

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 8/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 13
Complete
Mark 1 out of 1

 If you provide an empty method within an abstract class, the method is an abstract method even if you do not explicitly use the keyword
abstract when de ning the method.

Question 14
Complete
Mark 1 out of 1

Send us a message
You use the keyword ________ to reference a method in the superclass from a subclass.

Select one:
a. super
b. superObject

c. that
d. this

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 9/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 15
Complete
Mark 1 out of 1

Using which of the following, multiple inheritance in Java can be implemented?

Select one:
a. Private methods
b. Protected methods
c. Multithreading
d. Interfaces

Send us a message
Question 16
Complete
Mark 1 out of 1


The UML uses ________ before a member name to indicate that the member is protected.

Select one:
a. +
b. ?
c. #
d. -

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 10/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 17
Complete
Mark 1 out of 1

Which of these class relies upon its subclasses for complete implementation of its methods?

Select one:
a. Object class
b. abstract class
c. None of the mentioned
d. ArrayList class

Send us a message
Question 18
Complete
Mark 1 out of 1


Must a program respond to all events that its components generate?

Select one:
a. Yes---the program that is running must handle all events that happen in anywhere one the screen or mouse.
b. No---the operating system sends the program only those events it can handle.
c. No---it can safely ignore events that don't concern it.
d. Yes---if an event is generated that it can't handle it will bomb.

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 11/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 19
Complete
Mark 1 out of 1

You cannot create an instance of an abstract class using the new operator.

Select one:
a. true
b. false

Question 20
Complete

Send us a message
Mark 1 out of 1

To remove a node from the pane, use ________.

Select one or more:



a. pane.getChildren().removeAll(node);
b. pane.removeAll(node);
c. pane.getChildren().remove(node);
d. pane.remove(node);

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 12/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 21
Complete
Mark 1 out of 1

To place a node in the left of a BorderPane p, use ________.

Select one:
a. p.setEast(node);
b. p.placeLeft(node);
c. p.setLeft(node);
d. p.left(node);

Send us a message
Question 22
Complete
Mark 1 out of 1


Which of these is supported by method overriding in Java?

Select one:
a. Abstraction
b. Encapsulation
c. Polymorphism
d. None of the mentioned

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 13/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 23
Complete
Mark 1 out of 1

When should your program call repaint()?

Select one:
a. Only once when the frame is created.
b. Always---whenever any method nishes.
c. Never--that is the system's job.
d. Whenever it has made a change to what should be displayed in the Frame.

Send us a message
Question 24
Complete
Mark 1 out of 1


Which of the following statements correctly creates a Color object?

Select one or more:


a. new Font("Times", 34);
b. Font.font("Times", 34);
c. Font.font("Times", FontWeight.NORMAL, FontPosture.ITALIC, 34);
d. new Font(34);
e. Font.font("Times", FontWeight.NORMAL, 34);

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 14/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 25
Complete
Mark 0 out of 1

Assume Calendar calendar = new GregorianCalendar(). ________ returns the month of the year.

Select one:
a. calendar.get(Calendar.MONTH_OF_YEAR)
b. calendar.get(Calendar.WEEK_OF_YEAR)
c. calendar.get(Calendar.MONTH)
d. calendar.get(Calendar.WEEK_OF_MONTH)

Send us a message
Question 26
Complete
Mark 1 out of 1


Which of the following statements will set the background color of a button named stop to a color of red?

Select one:
a. setBack.stop.Color.RED;
b. stop.Backcolor = RED;
c. stop.setBackground(Color.RED);
d. red.setBackground(Color.RED);

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 15/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 27
Complete
Mark 1 out of 1

If super class and sub class have same variable name, which keyword should be used to use super class?

Select one:
a. this
b. super
c. classname
d. upper

Send us a message
Question 28
Complete
Mark 1 out of 1


An abstract class can be extended.

Select one:
a. true
b. false

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 16/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 29
Complete
Mark 1 out of 1

An application’s ability to select the correct subclass method is known as ____.

Select one:
a. dynamic method binding
b. method xing
c. implicit casting
d. implementing methods

Send us a message
Question 30
Complete
Mark 1 out of 1


If a user enters more characters than speci ed in a JTextField, the extra characters are deleted.

Select one:
a. False
b. True

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 17/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 31
Complete
Mark 1 out of 1

When you create a class and use the implements clause to implement an interface but fail to code one of the interface’s methods, the
compiler error generated indicates that you must declare your class to be ____.

Select one:
a. public
b. static
c. related
d. abstract

Send us a message
Question 32
Complete
Mark 1 out of 1

To add two nodes node1 and node2 to the the rst row in a GridPane pane, use ________.

Select one or more:


a. pane.add(node1, node2, 0);
b. pane.add(node1, 0, 0); pane.add(node2, 1, 0);
c. pane.add(node1, 0, 1); pane.add(node2, 1, 1);
d. pane.addRow(0, node1, node2);
e. pane.addRow(1, node1, node2);

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 18/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 33
Complete
Mark 1 out of 1

It is useful to override the parent class members when the superclass data elds and methods are not completely appropriate for the
subclass objects.

Select one:
a. False
b. True

Question 34

Send us a message
Complete
Mark 1 out of 1

How many GUI components can go into each cell with GridPane?

Select one:
a. 1
b. Only one Panel per cell.
c. As many as you need.
d. None

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 19/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 35
Complete
Mark 0 out of 1

Programmers and analysts sometimes use a graphical language to describe classes and object-oriented processes. This language is called
Uni ed Modelling Language .

Question 36
Complete
Mark 1 out of 1

Send us a message
Using the keyword ____ provides you with an intermediate level of security between public and private access.

Select one:
a. secure
b. super

c. this
d. protected

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 20/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 37
Complete
Mark 1 out of 1

If a parameter is of the java.lang.Object type, you can pass any object to it. This is known as generic programming.

Select one:
a. false
b. true

Question 38
Complete

Send us a message
Mark 0 out of 1

Analyze the following code:



Select one:
a. The constructor of class A is called and it displays "i from A is 40".
b. The constructor of class A is not called.
c. The constructor of class A is called and it displays "i from A is 60".
d. The constructor of class A is called and it displays "i from A is 7".

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 21/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 39
Complete
Mark 1 out of 1

. Usually, the subclass constructor only needs to initialize the ____ that are speci c to the subclass.

Select one:
a. methods
b. objects
c. data elds
d. constructors

Send us a message
Question 40
Complete
Mark 1 out of 1


To construct a Polygon with three points x1, y1, x2, y2, x3, and y3, use ________.

Select one or more:


a. Polygon polygon = new Polygon(); polygon.getPoints().addAll(x1, y1, x2, y2, x3, y3)
b. new Polygon(x1, y2, x3, y1, y2, y3)
c. Polygon polygon = new Polygon(); polygon.getPoints().addAll(x1, y2, x3, y1, y2, y3)
d. new Polygon(x1, y1, x2, y2, x3, y3)

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 22/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 41
Complete
Mark 1 out of 1

When you create a class and do not provide a(n) ____, Java automatically supplies you with a default one.

Select one:
a. argument
b. header
c. name
d. constructor

Send us a message
Question 42
Complete
Mark 1 out of 1


Which of the following statements are true?

Select one:
a. A Node can be placed in a Pane.
b. A Pane can be placed in a Control.
c. A Node can be placed in a Scene.
d. A Shape can be placed in a Control.

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 23/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 43
Complete
Mark 1 out of 1

Given the method declaration below,


public void m1(int num1, int num2){}

 
which method declaration overload method m1?

Select one:
a.
public void m1(int num1, double num2){}

Send us a message
b.
public string m1(int num1, int num2, int num3){}

c.
public int m1(int num1, int num2){}

d.
public void m2(int num1, int num2){}

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 24/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 44
Complete
Mark 1 out of 1

Assume an employee can work for only one company. What is the best suitable relationship between Company and Employee?

Select one:
a. Inheritance
b. None
c. Composition
d. Aggregation

Send us a message
Question 45
Complete
Mark 0 out of 1


Match each term with the correct statement below.

Can be used with the setBackground() and setForeground() methods of the Component class Color class

Distance between component increases with increasing frame size GridLayout

Use when you need to add components into rows and columns; each component is the same size BorderLayout

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 25/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 46
Complete
Mark 1 out of 1

Analyze the following code:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.geometry.Insets;
import javafx.stage.Stage;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

Send us a message
Select one:
a. new Image("www.cs.armstrong.edu/liang/image/us.gif") must be replaced by new
Image("http://www.cs.armstrong.edu/liang/image/us.gif").
b. The addAll method needs to be replaced by the add method.

c. The image object cannot be shared by two ImageViews.
d. The program runs ne and displays two images.

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 26/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 47
Complete
Mark 1 out of 1

Which of the following statements creates an array of three Animal references?

Select one:
a. Animal[] animalRef = new Animal[3];
b. Animal[] new = ref Animal[3];
c. Animal[] ref = extend Animal[3];
d. Animal[] ref = new Animal(3);

Send us a message
Question 48
Complete
Mark 1 out of 1


public B(Strign s) {

Select one:
a. The program would compile ne if you add the following constructor into A: A(String s) { super(s); }
b. The program has a compilation error because A does not have a default constructor.
c. The program would compile ne if you add the following constructor into A: A(String s) { }
d. The program has a compilation error because the default constructor of A invokes the default constructor of B, but B does not have
a default constructor.

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 27/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 49
Complete
Mark 1 out of 1

Which of the following statements is false?

Select one:
a. A public class can be accessed by a class from a di erent package.
b. A method with no visibility modi er can be accessed by a class in a di erent package.
c. A private method cannot be accessed by a class in a di erent package.
d. A protected method can be accessed by a subclass in a di erent package.

Send us a message
Question 50
Complete
Mark 0 out of 1


The UML uses ________ before a member name to indicate that the member is package-private.

Select one:
a. -
b. #
c. +
d. none (blank)

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 28/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 51
Complete
Mark 1 out of 1

Which of these is correct way of inheriting class A by class B?

Select one:
a. class B inherits class A {}
b. class B extends A {}
c. class B extends class A {}
d. class B + class A {}

Send us a message
Question 52
Complete
Mark 1 out of 1


All classes in Java are inherited from which class?

Select one:
a. java.class.object
b. java.lang.Object
c. java.lang.class
d. java.class.inherited

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 29/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 53
Complete
Mark 1 out of 1

What is the best suitable relationship between Employee and Faculty?

Select one:
a. Inheritance
b. None
c. Aggregation
d. Composition

Send us a message
Question 54
Complete
Mark 1 out of 1


Every class has a toString() method and an equals() method.

Select one:
a. false
b. true

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 30/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 55
Complete
Mark 1 out of 1

Which of the following statements are true?

Select one or more:


a. A strong is-a relationship describes a direct inheritance relationship between two classes.
b. A strong is-a relationship can be represented using class inheritance.
c. Inheritance models the is-a relationship between two classes.
d. A weak is-a relationship describes that a class has certain properties.
e. A weak is-a relationship can be represented using interfaces.

Send us a message
Question 56
Complete
Mark 0 out of 1

When a user closes a JFrame by clicking the Close button in the upper-right corner, the default behavior is for the JFrame to close and the
application to terminate.

Select one:
a. True
b. False

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 31/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 57
Complete
Mark 1 out of 1

An interface can extend any number of interfaces using the extends keyword.

Select one:
a. true
b. false

Question 58
Complete

Send us a message
Mark 0 out of 1

You can always successfully cast a superclass to a subclass.

Select one:

a. true
b. false

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 32/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

Question 59
Complete
Mark 1 out of 1

What is it called when a program is written to respond to the button clicks, menu selections, and other actions of the user in whatever order
the user does them?

Select one:
a. Event-driven programming.
b. Mouse-driven programming
c. User-driven programming.
d. Action-driven programming.

Send us a message
Question 60
Complete
Mark 0 out of 1

. As you add new Components to a ____, they are positioned in sequence from left to right across each row.

Select one:
a. HBox
b. CardPane
c. GridPane
d. BorderPane

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 33/34
10/05/2020 Mid Semester Exams 2020 Regular and Top-up

https://gtuconline.gtuc.edu.gh/online/mod/quiz/review.php?attempt=24233&cmid=6103&showall=1 34/34

You might also like