Docsity

COMPUTER LATEST PROGRAMMING EXAM ,COMPUTER LATEST PROGRAMMING EXAM COMPUTER LATEST PRO, Exams of Computer Fundamentals

Toggle sidebar
bg1
END OF
PAGE
1
ANSWER ALL QUESTIONS IN THIS SECTION
QUESTION 1
Which of the following is correct?
A) a parent class is a subclass of its child
B) a base class is a child class or derived class
C) a base class is a parent class or super class
D) a child class is a super class of its parent
E) None of these are correct - ANSWERS-C
QUESTION 2
An int array stores the following values: 9, 4, 12, 2, 6, 8,
Which of the following lists of numbers would accurately show the array after the
third pass of
the selection sort algorithm?
COMPUTER LATEST
PROGRAMMING EXAM
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26

Partial preview of the text

Download COMPUTER LATEST PROGRAMMING EXAM ,COMPUTER LATEST PROGRAMMING EXAM COMPUTER LATEST PRO and more Exams Computer Fundamentals in PDF only on Docsity!

END OF PAGE

ANSWER ALL QUESTIONS IN THIS SECTION

QUESTION 1

Which of the following is correct? A) a parent class is a subclass of its child B) a base class is a child class or derived class C) a base class is a parent class or super class D) a child class is a super class of its parent E) None of these are correct - ANSWERS-C QUESTION 2 An int array stores the following values: 9, 4, 12, 2, 6, 8, Which of the following lists of numbers would accurately show the array after the third pass of the selection sort algorithm?

PROGRAMMING EXAM

END OF PAGE

A) 9, 4, 12, 2, 6, 8, 18

B) 2, 4, 6, 9, 8, 12, 18

C) 2, 4, 12, 9, 6, 8, 18

D) 2, 4, 6, 9, 12, 8, 18

E) 2, 4, 9, 12, 6, 8, 18 - ANSWERS-D

QUESTION 3

Polymorphism is achieved by A) overloading B) overriding C) embedding D) abstraction E) encapsulation - ANSWERS-B

PROGRAMMING EXAM

END OF PAGE D) Retired E) This cannot be determined by examining the code - ANSWERS-E QUESTION 6 What class hierarchy involving classes L, M, and N would make the following code valid? L l; M m; N n; l = new M(); l = new N(); m = new N(); A) Classes M and N must both be subclasses of class L. B) Class M must be a subclass of class N, which is a subclass of class L. C) Class N must be a subclass of class M, which is a subclass of class L. D) Classes L must be a subclass of class M and also a subclass of class N. E) There is no class hierarchy that would allow this code. - ANSWERS-C

PROGRAMMING EXAM

END OF PAGE

QUESTION 7

What is printed by this code? int x = 0; for (int y = 1; y <= 10; y++){ if (y % 2 != 0) x++; } System.out.println(x); A) 0 B) 2 C) 5 D) 10 E) None of these - ANSWERS-C

PROGRAMMING EXAM

END OF PAGE What should the missing if expression be in order to make this method always return a value that is not less than 0? int mystery2 (int n){ if (<>) return - n; else return n; } A) n > 0 B) n != 0 C) n < 0 D) n > 1 E) None of these - ANSWERS-C Which of these statements is not true?

PROGRAMMING EXAM

END OF PAGE A) Java allows us to treat an object of a subclass as an object of a superclass. B) One cannot automatically consider a superclass object to be an object of a subclass. C) A class that contains an abstract method must itself be abstract. D) The subclass cannot directly access private members of a superclass. E) An abstract method cannot return a value. - ANSWERS-E Which of these statements about a subclass constructor calling a superclass constructor is true? A) The superclass constructor cannot be called directly from the subclass constructor B) The parameters for the subclass constructor must be the same as those for the superclass constructor. C) The superclass constructor can be called only if it does not take any parameters. D) The superclass default (no-parameter) constructor cannot be called from the subclass constructor. E) The call to the superclass constructor, if included, must be the first statement in the subclass

PROGRAMMING EXAM

END OF PAGE B) String name = new String("Harry Potter"); C) String name = "Harry" + " " + "Potter"; D) String name = new String("Harry" + " " + "Potter"); E) Any of these would work - ANSWERS-E Java is a strongly typed language. What is meant by "strongly typed"? A) Every variable must have an associated type before it can be used. B) Variables can be used without declaring their types . C) Every variable has a single type associated with it throughout its existence in the program and the variable can only store values of that type. D) Variables are allowed to change type during their existence in a program so long as the value a variable currently stores is of the type it currently declared to be. E) Variables are allowed to change types during their existence in a program but only if the

PROGRAMMING EXAM

END OF PAGE change is to a narrower type. - ANSWERS-C The String class's compareTo method A) compares two strings in a case-independent manner B) yields true or false C) yields 0 if the two strings are identical D) returns 1 if the first string comes lexically before the second string E) None of these - ANSWERS-C What happens if you declare a class constructor to have a void return type? A) You will receive a syntax error. B) The program will compile with a warning but you'll get a run-time error. C) There is nothing wrong with declaring a constructor with a void return type. D) The class's default constructor will be used instead of the one you're declaring. E) None of these - ANSWERS-A How can the following statement be rewritten using a conditional (ternary) operator?

PROGRAMMING EXAM

END OF PAGE int x = 10; do { System.out.println(x); x--; } while(x > 0); A) 0 times B) 1 time C) 9 times D) 10 times E) 11 times - ANSWERS-D Having multiple class methods of the same name where each method has a different number of or type of parameters is known as A) encapsulation B) method overriding C) method overloading

PROGRAMMING EXAM

END OF PAGE D) method overwriting E) information hiding - ANSWERS-C Identify the statement which is not true. A) Local variable lifetime is the run time of a single method. B) Instance variable lifetime is the lifetime of the containing object. C) Non-void methods must declare a return type. D) A local variable scope is the body of the method where the variable is declared. E) Formal parameter lifetime is the run time of the object containing the method. - ANSWERS-E Identify the statement which is not true. A) Non-void methods always take parameters. B) Non-void methods always contain a return statement. C) Non-void methods can return references to objects. D) An invocation of a method that returns a value can be used as an expression any place that a value of the type returned can be used.

PROGRAMMING EXAM

END OF PAGE Which of the following uses of variable name overloading would cause a compiler error? A) An instance variable named x and a local variable named x. B) A private method named m that takes an integer parameter and a private method named m that takes no parameters. C) An instance variable in class X named x and an instance variable in class Y named x. D) A parameter named x and a local variable named x. E) None of them - ANSWERS-D Identify the true statement. A) In Java, definition of one method can be enclosed in the body of another method. B) In Java, the names of parameters and corresponding arguments must be the same. C) A constructor is a method that is automatically called when an object is created. D) When a method exits, control always returns to the current object constructor. E) The keyword this refers to the method containing it. - ANSWERS-C

PROGRAMMING EXAM

END OF PAGE Which of these items you may find in a constructor? A) A definition of a new class B) A definition of a private method C) A call to a private method of the current object ('object in scope') D) A call to a private method of another object E) A declaration of an instance variable - ANSWERS-C Identify the true statement. A) Instance variables specify the actions that an object can perform. B) All objects of the same class have the same attributes, although the values stored in the attribute variables might be different. C) The value of an instance variable is set when the object is created and stays constant until the object is deleted. D) The number of attributes for a particular object can change during the running of a program.

PROGRAMMING EXAM

END OF PAGE If you declare a variable as an instance variable within a class, and you declare and use the same variable name within a method of the class, then within the method A) the variable declared inside the method takes precedence B) the class instance variable takes precedence C) the two variables refer to a single memory address D) an error will occur E) you will not be able to use the local variable - ANSWERS-A Variables that are shared by every instantiation of a class are A) private variables B) class variables C) public variables D) illegal E) instance variables - ANSWERS-B Assuming a variable y has been assigned the value 6, the value of !(y < 7) is

PROGRAMMING EXAM

END OF PAGE

A) 6

B) 7

C) true D) false E) None of these - ANSWERS-D What is the output of the following code? b = 1; while(b < 4) System.out.print(b + " "); A) 1 B) 1 2 3 C) 1 2 3 4 D) 1 1 1 1 1 1... E) 1 1 1 - ANSWERS-D What is the output of the following code? d = 0;

PROGRAMMING EXAM