0

programming languages Online Quiz - 318

Description: programming languages Online Quiz - 318
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

Which functions are available in SQL?

  1. string and date

  2. character and numeric

  3. integer and conversion

  4. calendar and date

  5. date and conversion

  6. translation and date


Correct Option: B,E

Which three are true?

  1. A MERGE statement is used to merge the data of one table with data from another.

  2. A MERGE statement can be used to update existing rows in a table.

  3. A MERGE statement replaces the data of one table with that of another.

  4. A MERGE statement can be used to insert new rows into a table.


Correct Option: A,C,D

Which statements are true about constraints?

  1. The UNIQUE constraint does not permit a null value for the column.

  2. The PRIMARY KEY and FOREIGN KEY constraints create a UNIQUE index.

  3. The NOT NULL constraint ensures that null values are not permitted for the column.

  4. A UNIQUE index gets created for columns with PRIMARY KEY and UNIQUE constraints.


Correct Option: A,C

Which statements about subqueries are true?

  1. A subquery should retrieve only one row.

  2. A subquery can retrieve zero or more rows.

  3. Subqueries CANNOT be nested by more than two levels.

  4. A subquery can be used only in SQL query statements.

  5. A subquery CANNOT be used in an SQL query statement that uses group functions.

  6. When a subquery is used with an inequality comparison operator in the outer SQL statement,


Correct Option: B,F

Which view should a user query to display the columns associated with the constraints on a table owned by the user?

  1. USER_CONSTRAINTS

  2. USER_OBJECTS

  3. ALL_CONSTRAINTS

  4. USER_CONS_COLUMNS

  5. USER_COLUMNS


Correct Option: D

The user Alice wants to grant all users query privileges on her DEPT table. Which SQL statement accomplishes this?

  1. GRANT select ON dept TO ALL_USERS;

  2. GRANT select ON dept TO ALL;

  3. GRANT QUERY ON dept TO ALL_USERS

  4. GRANT select ON dept TO PUBLIC;

  5. GRANT QUERY ON dept TO PUBLIC;


Correct Option: D

Which constraint can be defined only at the column level?

  1. UNIQUE

  2. NOT NULL

  3. CHECK

  4. PRIMARY KEY

  5. FOREIGN KEY


Correct Option: B

AI Explanation

To answer this question, you need to understand the different types of constraints that can be defined in a database.

Option A) UNIQUE - This option is incorrect because the UNIQUE constraint can be defined at both the column level and the table level. It ensures that the values in a specific column or combination of columns are unique.

Option B) NOT NULL - This option is correct because the NOT NULL constraint can only be defined at the column level. It ensures that a column must have a value and cannot be left empty or null.

Option C) CHECK - This option is incorrect because the CHECK constraint can be defined at both the column level and the table level. It allows you to specify a condition that must be satisfied for the data in a column.

Option D) PRIMARY KEY - This option is incorrect because the PRIMARY KEY constraint can be defined at both the column level and the table level. It uniquely identifies each row in a table and can be defined on one or more columns.

Option E) FOREIGN KEY - This option is incorrect because the FOREIGN KEY constraint can be defined at both the column level and the table level. It establishes a relationship between two tables based on a common column.

The correct answer is B) NOT NULL. This option is correct because the NOT NULL constraint can only be defined at the column level, ensuring that the column must have a value and cannot be null.

In which cases would you use an outer join?

  1. The tables being joined have NOT NULL columns.

  2. The tables being joined have only matched data.

  3. The columns being joined have NULL values.

  4. The tables being joined have only unmatched data.

  5. The tables being joined have both matched and unmatched data.

  6. Only when the tables have a primary key/foreign key relationship.


Correct Option: C,E

AI Explanation

To answer this question, you need to understand the concept of joins in database queries.

An outer join is used to combine rows from two or more tables based on a related column, including unmatched rows. It includes rows from both tables, even if there is no match between the columns being joined. Outer joins are useful when you want to include all the rows from one table, regardless of whether there is a match in the other table.

Let's go through each option to understand why it is correct or incorrect:

Option A) The tables being joined have NOT NULL columns. - This option is incorrect because the presence of NOT NULL columns does not determine whether an outer join should be used.

Option B) The tables being joined have only matched data. - This option is incorrect because an outer join is used to include unmatched data as well.

Option C) The columns being joined have NULL values. - This option is correct because an outer join is typically used when the columns being joined have NULL values.

Option D) The tables being joined have only unmatched data. - This option is incorrect because an outer join is used to include both matched and unmatched data.

Option E) The tables being joined have both matched and unmatched data. - This option is correct because an outer join is typically used when there is both matched and unmatched data between the tables.

Option F) Only when the tables have a primary key/foreign key relationship. - This option is incorrect because an outer join can be used even when there is no primary key/foreign key relationship between the tables.

The correct answer is C,E. This option is correct because an outer join is commonly used when the columns being joined have NULL values and when there is both matched and unmatched data between the tables.

Which of the following is not a joke from Chet Haase's humor blog:

  1. What do you call it when a chip manufacturer loses money? -- A cash miss.

  2. What do you call someone who has to use a dull web application? --Bored to tiers.

  3. What does a hungry vegetarian say? --"I´m so hungry, I could eat a tree."

  4. Always wear protective goggles when operating a weed-eater, working with a power tool, or teasing your wife.


Correct Option: C

Given: 11. public static void test(String str) { 12. int check = 4; 13. if (check = str.length()) { 14. System.out.print(str.charAt(check -= 1) +“, “); 15. } else { 16. System.out.print(str.charAt(0) + “, “); 17. } 18. } and the invocation: 21. test(”four”); 22. test(”tee”); 23. test(”to”); What is the result?

  1. r, t, t,

  2. r, e, o,

  3. Compilation fails.

  4. An exception is thrown at runtime.


Correct Option: C

Given: 11. public static void test(String str) { 12. int check = 4; 13. if (check = str.length()) { 14. System.out.print(str.charAt(check -= 1) +“, “); 15. } else { 16. System.out.print(str.charAt(0) + “, “); 17. } 18. } and the invocation: 21. test(”four”); 22. test(”tee”); 23. test(”to”); What is the result?

  1. r, t, t,

  2. r, e, o,

  3. Compilation fails.

  4. An exception is thrown at runtime.


Correct Option: C

A class games.cards.Poker is correctly defined in the jar file Poker.jar. A user wants to execute the main method of Poker on a UNIX system using the command: java games.cards.Poker What allows the user to do this? A. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java B. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/.jar C. Put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/Poker.jar D. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java E. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuffijava/.jar F. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/Poker.jar

  1. A

  2. B

  3. C

  4. D

  5. E

  6. F


Correct Option: C

What is the result of compiling and running this program? class Clove{ void quality(Clove m){ System.out.println("Clove is nice"); } } class Mint extends Clove{ void quality(Mint c){ System.out.println("Mint is ok"); } } class Sage extends Mint{ void quality(Sage h){ System.out.println("Sage is average"); } } public class Test{ public static void main(String[] args){ Clove h = new Sage(); Mint c = new Sage(); c.quality(h); } }

  1. prints "Clove is nice"

  2. prints "Mint is ok"

  3. prints "Sage is average"

  4. Class cast Exception at runtime.


Correct Option: A

What will this program print out ? class Base{ int value = 0; Base(){ addValue(); } void addValue(){ value += 10; } int getValue(){ return value; } } class Derived extends Base{ Derived(){ addValue(); } void addValue(){ value += 20; } } public class Test { public static void main(String[] args){ Base b = new Derived(); System.out.println(b.getValue()); } }

  1. 10

  2. 20

  3. 30

  4. 40


Correct Option: D

Given classes defined in two different files: 1. package util; 2. public class BitUtils { 3. private static void process(byte[] b) { } 4. } 1. package app; 2. public class SomeApp { 3. public static void main(String[] args) { 4. byte[] bytes = new byte[256]; 5. // insert code here 6. } 7. } What is required at line 5 in class SomeApp to use the process method of BitUtils?

  1. process(bytes);

  2. BitUtils.process(bytes);

  3. app.BitUtils.process(bytes);

  4. util.BitUtils.process(bytes);

  5. import util.BitUtils. *; process(bytes);

  6. SomeApp cannot use the process method in BitUtils.


Correct Option: F

class Abc { int i=initialize(369); int j=initialize(); public int initialize() { return 318; } public void initialize(int i) { this.i=i; } public static void main(String a[]) { Abc abc=new Abc(); System.out.println("i="+abc.i); abc.initialize(369); System.out.println("after i="+abc.i); System.out.println("j="+abc.j); } }

  1. Error: Non static method intialize cannot accessed from static context main

  2. Error: Method initialize is already defined

  3. i=0 after i=369 j=318

  4. Error: incompatible types


Correct Option: D

Given: 1. public class Threads4 { 2. public static void main (String[] args) { 3. new Threads4().go(); 4. } 5. public void go() { 6. Runnable r = new Runnable() { 7. public void run() { 8. System.out.print(”foo”); 9. } 10. }; 11. Thread t = new Thread(r); 12. t.start(); 13. t.start(); 14. } 15. } What is the result?

  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes normally and prints ‘foo”.

  4. The code executes normally, but nothing is printed.


Correct Option: B

Given classes defined in two different files: 1. package util; 2. public class BitUtils { 3. public static void process(byte[]) { /* more code here */ } 4. } 1. package app; 2. public class SomeApp { 3. public static void main(String[] args) { 4. byte[] bytes = new byte[256]; 5. // insert code here 6. } 7. } What is required at line 5 in class SomeApp to use the process method of BitUtils?

  1. process(bytes);

  2. BitUtils.process(bytes);

  3. util.BitUtils.process(bytes);

  4. SomeApp cannot use methods in BitUtils.

  5. import util.BitUtils.*; process(bytes);


Correct Option: C

Given: 11. // insert code here 12. private N min, max; 13. public N getMin() { return min; } 14. public N getMax() { return max; } 15. public void add(N added) { 16. if (min == null || added.doubleValue() max.doubleValue()) 19. max = added; 20. } 21. } Which two, inserted at line 11, will allow the code to compile? (Choose two.)

  1. public class MinMax> {

  2. public class MinMax extends Number> {

  3. public class MinMax {

  4. public class MinMax {

  5. public class MinMax extends Object> {

  6. public class MinMax {


Correct Option: D,F

class Abc { static { System.out.print("Static block "); display(); } public void display() { System.out.print("Display block "); } public static void main(String a[]) { System.out.print("Starting of Main block "); Abc abc=new Abc(); System.out.print("In the Main block "); abc.display(); } }

  1. Starting of Main block Static block In the Main block Display block

  2. Static block Display block Starting of Main block In the Main block Display block

  3. Error: Non static method cannot accessed from static context

  4. Starting of Main block In the Main block Display block


Correct Option: B
- Hide questions