KEMBAR78
Stud Bank Java Practice | PDF | Inheritance (Object Oriented Programming) | Class (Computer Programming)
0% found this document useful (0 votes)
7 views13 pages

Stud Bank Java Practice

Uploaded by

wujink
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views13 pages

Stud Bank Java Practice

Uploaded by

wujink
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Page 1 of 13

Java practice

Part A: True or False

1. A String is a primitive data type in Java.


True or False
2. Encapsulation means information hiding.
True or False
3. A class describes a set of object with similar attributes and behaviour.
True or False

4. public access modifier enforces information hiding.


True or false

5. Java source code is saved with the .class extension.


True or False.
6. Java source code is saved with the .java extension.
True or False.
7. Java bytecode ends with the .class extension.
True or False.
8. A local variable must be initialized before use.
True or False
9. The following statement
int[ ][ ] myArray = new int [3] [4];
is an example of one dimensional array declaration/creation.
True or False.

10. The following statement


int[ ][ ] myArray = new int [3] [4];
is an example of two dimensional array declaration/creation.
True or False.

11. Data hiding describes the term encapsulation.


True or False.
12. Like methods, constructors can be overloaded.
True or False.
13. protected access modifier allows visibility of data within a package.
True or False.
14. Constructors must have the same name as its class name.
True or False.
15. Like methods, constructors can have a return type or statement.
True or False.
16. Classes are instances of objects.
True or False.
17. Private access modifier enforces information hiding.
True or False.
18. Arrays are objects in Java.
True or False.
19. The following is an example of method overloading
add(int, int)
add(String, string)
True or False.

Page 1 of 13
Page 2 of 13

20. In aggregation and composition relationships, the diamond arrow point to the aggregated cl
ass.
True or False.

21. In aggregation and composition, the diamond arrow point to the aggregating class.
True or False.
1. private data member of a class can only be accessed by setter and getter method.
a. True or False.
2. The getter and setter methods access specifiers can be private.
a. True or False.
3. Private specifier for data fields ensures the safety of data values.
a. True or False.

4. The getter and setter methods have only public access specifiers.
a. True or False.
5. Access specifiers for constructors can be private.
a. True or False.
6. Methods having static in their method header can be called by a class instance.
a. True or False.
7. Wrapper classes are primitive types.
a. True or False.
8. Wrapper classes are reference types.
a. True or False.

9. Wrapper classes are reference types.


a. True or False.

10. In composition relationship, the aggregating class is used as a data field in the aggregated
class.
a. True or False.

11. In composition relationship, the aggregated class is used as a data field in the aggregating
class.
a. True or False.
12. Superclass constructors are inherited in the subclasses.
a. True or False.
13. Superclass constructors are not inherited in the subclasses.
a. True or False.

14. The super keyword is used to reference a superclass from inside a subclass constructor.
a. True or False.

15. A superclass’s properties and methods are inherited in the subclass.


a. True or False.
16. The this keyword can be used to reference a constructor name, like its use in referencing
object data.
a. True or False.
17. The this keyword cannot be used to reference a constructor name, as it is similarly used in
referencing object data.
a. True or False.
18. Superclass constructors are inherited in subclasses.
a. True or False.

Page 2 of 13
Page 3 of 13

19. Superclass constructors are not inherited in subclasses.


a. True or False.
20. Data fields and methods of superclasses are inherited in subclasses.
a. True or False.

21. Data fields and methods of superclasses are not inherited in subclasses.
a. True or False.
22. If a class is abstract, at least one of its methods must be abstract.
a. True or False.
23. Methods declared as abstract are not defined in their classes.
a. True or False.
24. In constructor chaining, superclasses constructors are implemented first before their
subclasses.
a. True or False.
25. In constructor chaining, subclasses constructors are implemented first before their
superclasses.
a. True or False.
26. Methods declared in interfaces have implementation detail.
a. True or False.
27. Methods declared in interfaces are defined.
a. True or False.

28. The finally block is always performed whether an exception is thrown or not.
a. True or False.
29. The try block is an exception handler.
a. True or False.
30. The catch block is an exception handler.
a. True or False.
31. Dividing 7 by 0 is a type of checked exception.
a. True or False.
32. The string “C:\MyJavaCode\Assignment\Person.java” is a relative filepath.
a. True or False.
33. The string “Person.java” is an absolute filepath.
a. True or False.
34. The string “Person.java” is a relative filepath.
a. True or False.
35. The subclasses of an interface use the extends keyword.
a. True or False.
36. The subclasses of an interface use the implements keyword.
a. True or False.
37. The subclasses of an abstract class use the extends keyword.
a. True or False.
38. The subclasses of an abstract class use the implements keyword.
a. True or False.
39. A subclass of an interface must implement all the inherited method from the interface.
True or False.
New
An instances of a subclass is also an instance of its superclass.
T or F

Page 3 of 13
Page 4 of 13

In constructor chaining, a subclass constructor is the first to be invoked before the its superclass
constructor call.
T or F
In constructor chaining, a superclass constructor is invoked before the execution of the subclass
constructor.
T or F
If a class is abstract, at least one of its methods must be abstract.
T or F.
An abstract method may not belong to an abstract class.
T or F
If a method is abstract, its class may not be abstract.
T or F
Abstract methods are fully defined for their client classes.
T or F
The implementation of abstract methods are left for their client classes.
T or F
Abstract method definitions are left for their client classes.
T or F

Given the following sum method;


int sum(int x, int y)
int sume(int a, int b )
The overloaded method shows a different signature.
T or F.
Given the following sum method;
int sum(int x, int y)
int sume(int a, int b )
The overloaded method shows the same signature.
T or F.
In a try and catch block, the catch block is always executed even when no exception is thrown.
T or F.
The finally block is always executed whether an exception object is thrown by a try and catch or not.
T or F.

Page 4 of 13
Page 5 of 13

Part B: Multiple Choice


22. Java has _____ number of primitive data types.
A) 6
B) 4
C) 2
D) 8

23. The reference variable of an object holds ___________________________ ?


A) data fields
B) memory address
C) class name
D) methods

24. __________ is used to make the scope i.e. the beginning and ending of classes and methods.
A) ( )
B) [ ]
C) { }
D) < >
25. __________ punctuation mark is used to end Java executable statement
A) ,
B) ;
C) .
D) ?
26. ________________ character marks Java single line comments
A) /**
B) /*
C) */
D) //

27. The Scanner class enables __________________


a. Input and output into a program
b. Output into a program
c. Input into a program
d. All of the above
28. One of the following modifiers ensures information hiding.

e. Public access modifier


f. Private access modifier
g. Private and public access modifier
h. None
29. During compilation, Java source code is compiled into _____
i. machine code
j. program output
k. bytecode
l. none
30. Before creating and opening a file, we check whether that filename has been created by the
___________________________ method?
m. hasNext()

Page 5 of 13
Page 6 of 13

n. nextLine()
o. exists()
p. equals()
31. Given the statement
int[ ][ ] myArray = new int [3] [4];
an element on the second row and third col can be referenced by
a. myArray[2][3]
b. myArray[1][3]
c. myArray[0][4]
d. myArray[1][2]

32. A UML class diagram is made up of the following parts except ______
a. operations
b. compiler
c. class name
d. attributes
33. A method signature is described to have all except one of the following. /
a. method name
b. datatype of parameter
c. a variable name
d. order of parameter list
34. This is a collection of programming statements that specify the fields and methods
that a particular type of object may have.
a. class
b. method
c. parameter
d. Instance

35. 2. A class is analogous to a(n) __________.


a. house
b. blueprint
c. drafting table
d. architect

36. 3. An object is a(n) __________.


a. blueprint
b. primitive data type
c. variable
d. instance of a class

37. 4. This is a class member that holds data.


a. method
b. instance
c. field
d. constructor

38. 5. This key word causes an object to be created in memory.


a. create
b. new
c. object
d. construct

Page 6 of 13
Page 7 of 13

39. One of the following is a method that is automatically invoked when a class instance is
created.
a. accessor
b. constructor
c. void
d. mutator
40. one of the following is automatically provided for a class if you do not create one yourself.
a. accessor method
b. default instance
c. default constructor
d. variable declaration
41. Polymorphism is the ability for many objects to ______________
a. Create own constructor
b. Adapt one method for self use
c. Create one object
d. Adapt to own variable

42. The relationship represented in the following diagram is a _____________

a. Aggregation
b. Composition
c. Dependency
d. Generalization
43. Given the following UML diagrams, which of the following does not apply.

a. Aggregation
b. Composition
c. Dependency
d. Inheritance
The concrete class that is implementing an abstract method must do all of these except
_______
a. Override the abstract method

Page 7 of 13
Page 8 of 13

b. Define the abstract method


c. Does not modify the abstract method
d. Can also declare the method abstract
New
One of the following options can be used to describe a method signature
a. returnType, methodName, parType, orderOfPar
b. parType, methodName, orderOfPar, numberOfPar
c. returnType, parType, methodName, numberOfPar
d. parType, returnType, numberOfPar, orderOfPar
The super keyword is used to reference a superclass ______________.
a. object
b. data fields
c. method
d. constructor

Part C: Fill-in the gap


1. Given the class name Person, write a statement that creates an instance of the class.

Answer:

2. _______________ is an example of a wrapper class type.

3. Conversion from wrapper class type to a primitive type is called ____________________

4. Conversion from a primitive type to a wrapper class type is called ____________________

Page 8 of 13
Page 9 of 13

Page 9 of 13
Page 10 of 13

Hint: Iterative for loop

Essay

9. By pen and paper, create a class diagram named Rectangle.

A. Specify its the length and width data field as private and the return type as double.
B. Write a no-argument constructor, and
C. mutator methods for the data fields;
D. a perimeter method of return types double and
E. area method of return types double.

Page 10 of 13
Page 11 of 13

Given the following Person class diagram; develop a complete program by defining all the methods
according to specification in the diagram.

Given the following Address and Person class diagrams; develop a complete program to implement
the related classes by defining all the methods according to specification in the diagram.

Given the following diagram, develop a complete code for the interface CalculateNumber, the
concrete subclass and the application to test your code using x = 7, y = 3.

Page 11 of 13
Page 12 of 13

a) Design a full program code according to the specification in the diagram.

b) create an instance of CidarApple class that is of type Fruit.

c) show by casting that the instance of CidarApple is also an instance of the Apple class.

a) Design a full program code according to the specification in the diagram.

b) create an instance of CidarApple class that is of type Fruit.

c) show by casting that the instance of CidarApple is also an instance of the Apple
class.

Page 12 of 13
Page 13 of 13

Write a method called divide(int num1, int num2) with a returntype of void. The method should
throw an exception if num2 = 0 if num1 is divided by num2.

Page 13 of 13

You might also like