OOP Final

What are the benefits of modeling using Object Oriented Design include:
Code reuse
Information hiding
Modularity
Debugging ease
All the above
Class variables are any field declared with the keyword static. When a class member is defined using static, how many copies of this member will there be relative to the number of times the class has been instantiated?
None regardless of how many instances of the class have been declared
One for each instance of the class declared
One regardless of how many instances of the class are declared
They are constant and cannot be changed
None of the above
A unique aspect of some object-oriented programming languages is not having to explicitly declare a class constructor. This is true with the Java programming language. When instantiating an instance of a class and a class constructor has not been explicitly declared how is the following source code valid: Bicycle bike1 = new Bicycle();?
It is not valid
The compiler automatically provides a no-argument constructor
There would be a compiler error
There would be no runtime error
It is considered an overloaded method
Regarding object-oriented programming, when an object is instantiated the keyword new is used, memory is allocated, and a reference to that memory is returned
True
False
String name1 = new String("Jon");
String name2 = name1;
name1 = new String("Jon");
System.out.println(name1 == name2);
True
False
Jon == Jon
None of the above
public class Calculator {int num = 100;public void calc(int num) {this.num = num * 10;}public void printNum(){System.out.print("The result of the calculation is : ");System.out.println(num);}public static void main(String[] args) {Calculator obj = new Calculator ();obj.calc(2);obj.printNum();}}
The result of the calculation is : 200
The result of the calculation is : 20
The result of the calculation is : 100
None of the above
List<String> list = new ArrayList();list.add("A");list.add("B");list.add("C");list.add("D");for (int I = 0; I < list.size(); i++)System.out.print(list.remove(i));
ABCD
AC
DCBA
DB
None of the above
class Test{public static void main(String[] args) {int x = 2;int y = 3;System.out.println(x+y/x+y%x);}
4.5
4
2.5
None of the above
String[] sa = {"tom ", "jerry "};for (int x = 0; x < 3; x++) {for (String s : sa) {System.out.print(x + " " + s);if (x == 1) {break;}}}
 
 
0 tom 0 jerry 1 tom 2 tom 2 jerry
0 tom 0 jerry 2 tom 2 jerry
0 tom 0 jerry 1 tom 1 jerry 2 tom 2 jerry
None of the above
int counter = -1;for (counter=1;counter<=3;++counter){if (counter <= 1) {System.out.print("UCF");}}if (counter == 4)System.out.print("UCF");
UCFUCFUCFUCF
UCFUCFUCF
UCFUCF
UCF
int counter = -1;for (counter=1;counter<=3;++counter){if (counter <= 1) {System.out.print("UCF");break;}}if (counter == 4)System.out.print("UCF");
UCFUCFUCFUCF
UCFUCFUCF
UCFUCF
UCF
String s1 = "abc";String s2 = "abc";String s3 = new String("abc");System.out.print("A");if (s1 == s2){if (s1 != s3){if (s2 == s3)System.out.print("B");}elseSystem.out.print("C");}
A
AB
AC
None of the above
Employee[] company;company = new Employee[3];for (int i=0;i<3;++i){company[i] = new Employee();}for (Employee e : company){System.out.print(e);}class Employee{public String toString() {return "employee";}}
EmployeeEmployeeEmployee
Eee
Employeeemployeeemployee
None of the above
int score = 65;switch (score/10%10){case 6: System.out.print (“UCF”);case 7: System.out.print(“UCF”);default: System.out.print(“UCF”);}if (score == 6)System.out.print(“UCF”);
UCF
UCFUCF
UCFUCFUCF
UCFUCFUCFUCF
Integer i1 = new Integer(1);Integer i2 = new Integer(2);Integer i3 = new Integer(3);i1 = i2;i2 = i3;i3 = i1;System.out.print(i1);System.out.print(i2);System.out.print(i3);
231
232
321
123
class Test{public static int a = 3;public static int b = 2;public static void setAll(int a, int b){Test.a = a;Test.b = b;}public Test(){Test.setAll(2,3);}public void print() {System.out.println("a = "+a+", b = "+b);}}...Test t = new Test();t.print();
A = 2, b = 3
A = 3, b =2
None of the above
public static int doSomething(int a, int b){return ++a + b--;}...int x = 2;int y = 3;y = doSomething(x,y);System.out.println(x+","+y);
2,6
3,5
2,5
3,5
None of the above
String names[] = new String[3];int I =0;for (i=0;i<3;++i)names[i] = new String("Abc");names[i] = new String("Xyz");for (i=0;i<3;++i)if (i < 4)System.out.print(names[i]);
XyzAbcAbc
AbcAbcAbcXyz
AbcAbcXyz
None of the above
class Test{private boolean flag = false;public Test(boolean flag){this.flag = flag;}public String toString() {return “false;}}...Test t = new Test(true);System.out.println(t);....
True
False
None of the above
class Test{int calculate() {return 1;}public static void main(String[] args){System.out.println(calculate());}}
1
None of the above
Cannot make a static reference to the non- static method calculate() from the type Test
class Test{public static int x;public static int y;public Test(){x = 6;y = 8;}public static void main(String[] args){Test t = new Test();System.out.println(Test.x+","+Test.y);}}
0,0
6,8
8,6
None of the above
public class Question {private int m_val;private void method1 () {method2();m_val = 1;}public int getVal(){return m_val;}public static void main(String args []) {Question q = new Question ();q.method1 ();method2();}private static void method2() {System.out.print((new Question ().getVal() +" "+ new Question ());}public Question() { m_val = 5; }public String toString() { return "6"; }}
5 15 1
5 65 6
5 65 5
5 61 6
How many super-classes can a subclass extend when using inheritance in object-oriented programming using the Java programming language?
Zero
One
Two
Unlimited
When defining classes in the Java programming language a software developer can extend __________ superclasses and implement __________ interfaces.
One, unlimited
Unlimited, one
Unlimited, two
Unlimited, unlimited
Which classes are instantiable?
class C{}
abstract class B extends C {}
class A extends C{}
B and C
A and C
A and B
None of the above
What methods does the class Class2 have to override?
interface Interface1 {
public void method1();
}
interface Interface2 {
public void method2();
}
abstract class Class1 implements Interface1 {}
class Class2 extends Class1 implements Interface2 {}
Only method1
Only method2
Method1 and method2
None of the methods
class Parent {
private int data;
public Parent(int data) { this.data = data;}
public int getData() { return data; }
public void printData() { System.out.print(data);
}
}
class Child extends Parent {
private String name;
public Child(int data, String name) {
super(data);
this.name = name;
}
@Override
public void printData() {
System.out.print(name + getData());
}
}
public class Main {
public static void main(String[] args) {
Parent pc = new Child(1, "UCF");
pc.printData();
}
}
1
UCF1
UCF0
None of the above
public class Main {public static void main(String args[]) {String myString = null;try {System.out.print(myString.length() + 5);System.out.print("1");} catch (NullPointerException npe) {System.out.print("1");} catch (Exception e) {System.out.print("1");} finally {System.out.print("1");}}}
911
11
91
None of the above
public class Main {public static void main(String args[]) {A a = new A();B b = new B();C c = new C();c = a;b = a;System.out.println(b);}}class A extends B {public String toString() {return "1";}}class B extends C {public String toString() {return "2";}}class C {public String toString() {return "3";}}
3
2
1
None of the above
public class Main {public static void main(String args[]) {boolean goAgain = true;while (goAgain == true) {try {int x = 5 / 0;if (goAgain == false)System.out.print(x);goAgain = false;System.out.print("1");} catch (Exception e) {goAgain = true;System.out.print("2");} finally {System.out.print("3");goAgain = false;}} // end of while}}
23
3
13
None of the above
public class Main {public static void main(String args[]) {A ref = new B();ref.data = 3;int data = 4;ref.show();}}class A {public int data;public A() { data = 7; }public void show() {System.out.println(data);}}class B extends A {public void show() {System.out.println(data);}}
7
3
4
None of the Above
ublic class Main {public static void main(String args[]) {A ref = new B();ref.data = 3;int data = 4;ref.show(7);}}class A {public int data;public void show() {System.out.println(data);}}class B extends A {public void show(int data) {System.out.println(data);}}
7
3
4
None of the above
class DivisionByZero extends Exception {public String toString() {return "9";}}public class Main {public static void main(String args[]) {try {int x = 1, y = 3;System.out.print(y / x - x);throw new DivisionByZero();} catch (DivisionByZero dbz) {System.out.print(dbz);} catch (Exception e) {System.out.print("1");} finally {System.out.print("1");}}}
1
291
11
None of the above
public class Main {public static void main(String args[]) {A ref = new B();ref.data = 3;int data = 4;((B) ref).show(7);}}abstract class A {public int data;public void show() {System.out.println(data);}}class B extends A {public void show(int data) {System.out.println(data);}}
7
3
4
None of the above
class MyAbstract {public int doNothing() {System.out.print("abc");return 1;}}public class Main extends MyAbstract {public static void main(String args[]) {MyAbstract a = new MyAbstract();doNothing(a.doNothing());}public static void doNothing(int dummy) {System.out.print("xyz");}}
Abcxyz
Xyz
Abcabc
None of the above
public class Main {public static void main(String args[]) {String[] array = new String[2];int I = 1;try {for (i = 0; I < 2; i++) {array[i] = new String("9");System.out.print(array[i-1]);}} catch (Exception e) {System.out.print("!");}}}
!
G!
G
None of the above
public class Main {public static void main(String args[]) {String[] array = new String[2];int I = 1;try {for (i = 0; I < 2; i++)array[i] = new String("9");System.out.print(array[i-1]);} catch (Exception e) {System.out.print("!");}}}
!
G!
G
None of the above
public class Main {public static void main(String args[]) {String[] array = new String[2];String str;int I = 1;try {for (i = 1; I < 3; i++)array[i-1] = new String("9");System.out.print(array[i-1]);} catch (Exception e) {System.out.print("!");}}}
!
G!
G
None of the above
public class Main {public static void main(String args[]) {Test test1 = new Test() , test2 = new Test();test1.data = 2;test2.data = 1;System.out.print( test1.compareTo(test2) + " " + test2.compareTo(test1));}}class Test implements Comparable <Test>{public int data;public int compareTo( Test obj) {if ( this.data < 2 + obj.data ) return 1;return 0;}}
1 0
0 1
1 1
0 0
public class Main {public static void main(String[] args) {Manager manager = new Manager();manager.salary = 33;System.out.println(manager);}}abstract class Person {abstract public int returnCode();}interface Printable {public void print();}abstract class Employee extends Person implements Printable {public int salary;public int returnCode() { return 30; }}class Manager extends Employee {public void print(double salary) {System.out.println(salary);}public String toString() {return "COP" + salary + returnCode();}}
COP3330
COP63
COP3033
None of the above
public class Main {public static void main(String args[]) {int[] array = {1, 2};int elem;try {elem = 3;throw new MyException();} catch (MyException me) {System.out.print(me);} finally {System.out.print("!!!");}}}class MyException {public String toString() {return "My Exception";}}
!!!
My Exception
My Exception!!!
None of the above
class Parent {public int x;public Parent() {x = 1;}}class Child extends Parent {private int x;public Child(int x) {this.x = x;x = super.x;}public void print(int x) {System.out.print(super.x + " " + x + " " + this.x);}}public class Main {public static void main(String args[]) {Parent pc = new Child(2);((Child) pc).print(3);}}
1 3 1
2 3 2
1 3 2
None of the above
abstract class Vehicle {public abstract void move(int miles);public void printInfo() { System.out.print("Vehicle "); }}public class Car extends Vehicle {private int distance;public void move(int miles) {distance = distance + miles;}public void printInfo() { System.out.print("Car "); }public static void main(String args[]) {Vehicle myVehicle = new Vehicle();Car myCar = new Car();myVehicle.printInfo();myCar.printInfo();}}
Vehicle
Vehicle Car
Car
None of the Above

public class Main {

public static ListNode method1(ListNode head) {

ListNode list = head;

while(list Is null) {

if (list.mNext == null) {

break;

}

if (list.mVal == list.mNext.mVal) {

list.mNext = list.mNext.mNext;

} else {

list = list.mNext;

}

return head;

}

}

What will be linked-list after calling method1 using the head=1,2,2,2,3,3,4,57

 

122345
12345
2345
None of above

public class Main {

public static ListNode method1 (ListNode head, int val) {

ListNode tmp = head;

ListNode node = new ListNode (val);

if(head == null) {

return node;

}

while(tmp.mNext I= null) {

tmp = tmp.mNext;

}

tmp.mNext = node;

node.next = null:

 

return head;

}

}

What will be linked-list after calling method1 using the head=1,2,2,2,3,3,4,5 and val=2?

 

1223452
123452
122233452
None of the above

public class Main {

boolean method1 (Node head){

Node slows head;

boolean result = true;

Stack<Integer> stack = new Stack<integer>();

while (slow Is null) {

stack.push(slow.mVal):

slow = slow.mNext;

}

while (head I= null){

int I = stack.popt;

if (head.mVal l= i) {

result = false;

break;

}

head a head.mNext;

}

return result;

}

 

What will be linked-list after calling method1 using the head=1,2,2,2,3,3,4,57

 

True
False
None of the above

public class Main {

List Node method1(ListNode head){

ListNode prev = null;

ListNode current = head;

List Node next = null;

while (current I= null) {

next = current.mNext;

current.mNext = prev;

prev = current;

current = next;

}

head = prev;

return head;

}

}

What will be linked-list after calling method1 using the head=1,2,2,2,3,3,4,5?

 

12345
54321
12223345
54332221

public class Main{

static void method1(Node head)

{

ListNode temp = head;

if (head le null){

do {

System.out.print(temp.mVal +" =);

temp = temp.mNext;

} while (temp I= head);

}

}

What will be output after calling method1 using the circular linked list head 1,2,2,2,3,3,4,5?

 

12345
122233451
1223345
54332221
{"name":"OOP Final", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"What are the benefits of modeling using Object Oriented Design include:, Class variables are any field declared with the keyword static. When a class member is defined using static, how many copies of this member will there be relative to the number of times the class has been instantiated?, A unique aspect of some object-oriented programming languages is not having to explicitly declare a class constructor. This is true with the Java programming language. When instantiating an instance of a class and a class constructor has not been explicitly declared how is the following source code valid: Bicycle bike1 = new Bicycle();?","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}
Powered by: Quiz Maker