CS 203 FINAL

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is the output of the following code snippet? public class Main { public static void main(String[] args) { int i = 0; while (i++ < 5) { System.out.print(i + " "); } } }

1 2 3 4 5

What is the expected output of the following code? public class Main { public static void main(String[] args) { int x = 10; System.out.println(x++); System.out.println(++x); }}

10 12

What is the output of the following code? public static void main(String args[]) { int x = 10; for (int y=0; y<5; y++, x--) System.out.print(" " + x); }

10 9 8 7 6

What is the output of the following code snippet? public class Example { public static void main(String[] args){ int x = 5; int y = 2; System.out.println(x / y); }}

2

What is the output of the following code snippet? public class Main { public static void main(String[] args) { int x = 5; float y = x / 2; System.out.println(y); }}

2.0

What is the output of the following code snippet? public static void main(String[] args) { double price = 49.99; int discount = 20; double discountedPrice = price - discount; System.out.printf("%.2f%n",discountedPrice); }

29.99

If you want your condition to depend upon two conditions BOTH being True, what is the proper notation to put between the two Boolean statements?

&&

What will be the output of the following code snippet? public class Main { public static void main(String[] args) { for (int i = 0; i < 5; i++) { if (i == 2) continue; System.out.print(i + " "); }}}

0 1 3 4

What is the output of the following code snippet? public class Example { public static void main(String[] args) { int i = 0; while (i < 5) { System.out.print(i + " "); i += 2; }}}

024

_________ is the base class (super class) of all classes in java.

Object

Which of the following is not true about overriding a method?

Overriding is not supported by JAVA

Which of the following statements is not True?

References are mutable

The ________ class allows the user to input data from his or her keyboard.

Scanner

Which data type is used to create a variable that should store text?

String

Method overloading is a feature of OOPs which makes it possible to give the same name to more than one method within a class if the arguments passed differ.

True

There is no need to create an object to call the static methods.

True

When we extend a superclass we have a choice whether or not to override the methods of the superclass

True

Which of the following is not True about Unit Testing?

Unit testing means testing one java package at a time

Which statement is not True about the Classes?

All classes must include a main() method

Which of the following statement is not True about JAVA variables?

An instance variable shared by all instances of the class

____________ is an unordered sequence that stores references to objects

Arraylist

Which of the following is true about arrays in Java?

Arrays have a fixed size once created.

What is the output of the following code? //Assume the following is located in A.java file public class A { void display() { System.out.println("A"); }} //Assume the following is located in B.java file public class B extends A {void display() { System.out.println("B"); }} //Assume the following is located in Main.java file public class Main { public static void main(String[] args) { A obj = new B(); obj.display(); }}

B

If the Class B inherits from Class A, which of the following cannot be said:

B has access to private methods of A

What is the output of the following code snippet? public class Main { public static void main(String[] args) { int number = 10; System.out.println("Before calling modifyValue method: " + number); modifyValue(number); System.out.println("After calling modifyValue method: " + number); }public static void modifyValue(int value) {value = 20;System.out.println("Inside modifyValue method: " + value); }}

Before calling modifyValue method: 10 Inside modifyValue method: 20 After calling modifyValue method: 10

What identifier sets a variable as true or false?

Boolean

Assume we have a base (parent) class Vehicle and a derived (child) class Car. Which of the following object creation is not possible?

Car carObj = new Vehicle();

What is the output of the following code snippet? public class Main { public static void main(String[] args) { int x = 5; boolean condition = (x > 0) && (x < 10) || (x % 2 == 0); if (condition) { System.out.println("Condition is true."); } else { System.out.println("Condition is false."); }}}

Condition is true.

Which of the following statement is not True about JAVA constructors?

Constructors can't be inherited.

What is the result of the following code snippet? int num = 6.45;

Error

Encapsulated Class is a OOP concept where one object can have many forms.

False

Instance variables belong to the class not any specific object

False

It is good practice for instance variables to be public.

False

The following is a correct statement to create a subclass public class Faculty extends UABEmployee,Researcher{}

False

We can only construct one object per class

False

We can store the integer values inside an arraylist using the following code; Arraylist <int>

False

What will be the output of the following code? public static void main(String[] args) { String str1 = new String("CS203"); String str2 = new String("CS203"); System.out.println(str1 == str2);}

False

When we are overriding an inherited method, we can use a different type of input parameters

False

What is the output of the following code? public class Main { public static void main(String[] args) { int a = 10;int b = 20;boolean c = false; if ( (a >= 10) && (b < 30) && (!c)) { System.out.println("Hello CS203"); } else { System.out.println("Good Luck");}}}

Hello CS203

Which of the following statement is not True about JAVA inheritance?

In Java, a class can extend multiple classes simultaneously.

Which of the following statements about Object-Oriented Programming (OOP) concepts is correct?

Inheritance allows a class to acquire the properties and methods of another class.

Which statement is not True about the Classes?

Inheritance is mandatory for all classes

Constructors are used to ____________

Initialize a newly created object

Which of the following is true about the private access modifier?

It allows access to the members only within the same class.

Which of the following statement is not true about JAVA?

It is an interpreted language

________________ is used to run the bytecode on each platform.

Java Virtual Machine

Which statement is not True about local variables?

Local variables can be used in any other method

What is the correct way to create an object called myObj of MyClass?

MyClass myObj = new MyClass();

Which of the following statement is not True about JAVA object?

The object can have only one type of data

Which of the following statement is not True about JAVA object?

The object can have only public methods

Which of the following statement is not True about JAVA?

The white spaces and the indentation is important

What is the role of the static keyword in Java?

To indicate that a method belongs to the class rather than an instance.

A derived Class automatically has all the instance variables and public methods that the base Class has, and it can have additional methods and/or instance variables as well

True

A side effect of a method is any externally observable data modification

True

Do - while loop is guaranteed to run at least one time

True

Every variable in JAVA need a data type

True

In the OOP concept, data and code are bound together by encapsulation

True

JAVA supports multilevel inheritance

True

Local variables belong to methods that they are created in

True

Which of the following is true about the public access modifier?

Variables, methods and constructors which are declared public can be accessed by any class

Which statement is used to stop a loop?

break

Which keyword is used to create a class in Java?

class

Within Java, you need to code your program so that under certain conditions it will skip the current iteration of a for loop. What can be used to accomplish this?

continue

Which of the following is not a primitive type?

object

When the child class declares a method that has the same type arguments as a method declared by its parent class is called as _____________

overriding

Assume you have two methods in the Parent class public void method1(){ ... } private void method2(){...} Which of the following is not Possible for the inherited subclass?

private void method1(){...}

Which of the following is not True about constructors ?

return type of the constructor is always int

_______ is a keyword which is used to access the methods or member variables of the parent class

super

_______ refers to the object a method is being called on.

this

Variables should usually be private

true

The operation _________ yields true if either or both of its operands are true.

||


Set pelajaran terkait

CH 9, 10, 11 Theories of Personality Feist 9th ed. Maslow, Rogers, May

View Set

Chapter 3 - Taxes in your financial plan

View Set

Anatomy Chapter 2.1, 2.2, 2.3 (Atoms, Ions, Molecules)

View Set

Forest Protection, Conservation, and Development

View Set

Test.1.1.Domestic versus International Logistics

View Set