Docsity

Practice Quiz Questions - Intermediate Programming | CS 251L, Quizzes of Computer Science

Partial preview of the text

Download Practice Quiz Questions - Intermediate Programming | CS 251L and more Quizzes Computer Science in PDF only on Docsity!

CS251 Intermediate Programming

Lecture 11

GUIs #

  • Midterm Wednesday, October 22.• Homework 3 due October 15.• Quiz 3 Wednesday, October 15, on GUIs.

Estimated Grade Ranges

Each question was

graded on a 5-point

scale. The total possible

was 75.

For 2 & 3, Assume you have this class:

Lecture 5, p. 46

{ public class C {public static void main(String[] args)private int b;private static int a;  o.b = 12;n.b = 7;m.b = 5;o.a = 5;n.a = 4;m.a = 3;C o = m;C n = new C();C m = new C();

}

  1. At the point marked}

(^) what are the values of:

m.a? ___, n.a? ___, o.a? ___, m.b? ___, n.b? ___, o.b? ___

C

m

n

o

For 2 & 3, Assume you have this class:

Lecture 5, p. 46

{ public class C {public static void main(String[] args)private int b;private static int a;  o.b = 12;n.b = 7;m.b = 5;o.a = 5;n.a = 4;m.a = 3;C o = m;C n = new C();C m = new C();

}

  1. At that point, how many copies of the variable }

(^) C.a

exist? ___ How many of

(^) C.b

? ___

C

m

n

o

  1. Given the partial class:

Lecture 5, p. 46

{ public class T public static void f(T t) { }private int getA() { return a; }private int a;

}

 (^) • Execute

T t2 = new T();

 (^) • Call

t.getA();



  • Call

getA();



  • Print the value of

this.a

 (^) • Print the value of

t.a

of Which of the following things could you do inside the body (^) f()

?

No

(^) this

(^) needed–constructor

NeedExplicit reference present

(^) this

(^) to call method

this

(^) unde

fi ned

Explicit reference

6-7. Pick two of the

(^) fi ve criteria for modularity and name

and brie

fl y describe both.

Lecture 6, p. 3

Protection: It can confine the consequences of failure or prevent them from spreading too far.Continuity: It can adjust smoothly to requirements changes.Understandability: It can be studied on its own, apart from the system it is a part of.Composability: It can be combined with other modules to form new systems. Decomposability: Module can be pulled out of the system and still maintain its integrity.

methods?9. Which object type(s) are allowed to have abstract

Lecture 8, p. 4

Interfaces, Abstract Classes, Concrete Classes

method implementations methods?10. Which object type(s) are allowed to have concrete

Lecture 8, p. 4

Interfaces, Abstract Classes, Concrete Classes

  1. If the following function is called:

Lecture 8, p. 14

{ public int aspen() { tryInteger a = null; System.out.print("a");return a.intValue();

{ catch (NullPointerException e)} System.out.print("b");

return 0;System.out.print("c");}

b) What value will the function return? a) What will be printed by the function? }

0 bc

Continues normally after Exception thrown, control transferred

(^) try

/ catch

(^) block

interfaces?13. Which of the following things can you do with

Lecture 7, p. 23

 (^) • Associate an "aspect" of an object with certain methods.



  • Guarantee that a class contains certain data

(^) fi elds.

 (^) • De

fi ne a new data type that an object can be tested for using

(^) instanceof

.

 (^) • Declare an object reference using the interface as the type of the reference.



  • Create an instance of the interface using

(^) new

.

description:15. Match the object-orientation principle with its

Lecture 7, p. 71

Encapsulation

  • Method calls can bind to di

 erent method implementations at runtime.

Polymorphism

  • Method implementations are shared between classes.

Inheritance

  • Not all class features are visible to other classes.

same time in order to start creating our own screens: We have to introduce several interlocking concepts at theIntroducing Containers/Components/Layout

JComponent

: something that takes up space in a window

JPanel interacts with the mouse or keyboard.)and has a look and feel. (Look: has an appearance. Feel:

: an invisible container that holds components.

JFrame

: a window with normal window controls.

LayoutManager

: an object that arranges components in

JButton a container.

, JLabel

: example components.

Components (2)

JFC components are subclasses of

(^) javax.swing.JComponent

.

Methods ofreason to manually set the location and size of a component.Once we introduce layout managers, there won’t be much

(^) JComponent

(^) include (most-used marked with

(^) ☞

):

Some components are outlined in red.