0% found this document useful (0 votes)
395 views31 pages

CSS Basics: Styles and Properties Guide

The document provides sample questions and answers about CSS, HTML, and background styles. It includes 10 multiple choice questions each on CSS, covering topics like CSS selectors, properties, and different styles (internal, external, inline). It also includes 10 multiple choice questions each on HTML and background styles in CSS. The questions test fundamental concepts and properties related to these topics.

Uploaded by

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

CSS Basics: Styles and Properties Guide

The document provides sample questions and answers about CSS, HTML, and background styles. It includes 10 multiple choice questions each on CSS, covering topics like CSS selectors, properties, and different styles (internal, external, inline). It also includes 10 multiple choice questions each on HTML and background styles in CSS. The questions test fundamental concepts and properties related to these topics.

Uploaded by

GOPI NADH P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

UNIT 3

WEB DESIGNING, OBJECT ORIENTED PROGRAMMING LANGUAGE, RDBMS


CSS

1. What does CSS stand for?


a. Cascading Style Sheet
b. Computer Style Sheet
c. Creative Style Sheet
d. Colorful Style Sheet
Answer: a

2. Which HTML tag is used to link an external CSS file to an HTML document?
a. `<style>`
b. `<link>`
c. `<css>`
d. `<script>`
Answer: b

3. What is the purpose of the 'box model' in CSS?


a. To create 3D effects
b. To define the layout and spacing of an element
c. To style text inside a box
d. To create rounded corners
Answer: b

4. Which CSS property is used to change the text color of an element?


a. `font-color`
b. `text-color`
c. `color`
d. `font-style`
Answer: c

5. What is the default value of the 'position' property in CSS?


a. absolute
b. relative
c. fixed
d. static
Answer: d

6. Which CSS selector is used to select all elements with a specific class?
a. #class
b. .class
c. class
d. *class
Answer: b

7. What is the purpose of the 'z-index' property in CSS?


a. It controls the visibility of an element
b. It controls the stacking order of elements
c. It sets the background color of an element
d. It changes the font size of an element
Answer: b

8. How can you center an element horizontally in CSS?


a. `text-align: center;`
b. `margin: auto;`
c. `align: center;`
d. `horizontal-align: center;`
Answer: b

9. Which CSS property is used to add shadows to text?


a. `text-shadow`
b. `box-shadow`
c. `shadow-text`
d. `text-outline`
Answer: a

10. What does the 'media query' in CSS allow you to do?
a. Print the stylesheet
b. Apply styles based on device characteristics
c. Link multiple stylesheets
d. Import external stylesheets
Answer: b

INTERNAL STYLES

1. Where are internal styles defined in an HTML document?


a. In a separate CSS file
b. In the `<head>` section using `<style>` tags
c. In the `<body>` section using `<style>` tags
d. Inline within HTML elements
Answer: b

2. What is the advantage of using internal styles over inline styles?


a. Easier to override
b. Better performance
c. Greater specificity
d. More flexibility
Answer: d

3. How do you comment out CSS code within the `<style>` tag for internal styles?
a. `/* This is a comment */`
b. `<!-- This is a comment -->`
c. `// This is a comment`
d. `# This is a comment`
Answer: a

4. Can an HTML document have more than one set of internal styles?
a. Yes, but it is not recommended
b. No, only one set is allowed
c. Yes, and it is common practice
d. No, it will result in an error
Answer: c

5. Which HTML tag is used to define internal styles?


a. `<css>`
b. `<style>`
c. `<script>`
d. `<link>`
Answer: b

6. What is the purpose of the 'scoped' attribute in the `<style>` tag?


a. It limits the styles to only the parent element
b. It prevents the styles from being applied
c. It allows styles to be inherited by child elements
d. It has no effect on internal styles
Answer: a

7. How do you select an element with an ID in internal styles?


a. `#elementID { ... }`
b. `.elementID { ... }`
c. `elementID { ... }`
d. `ID: elementID { ... }`
Answer: a

8. Which CSS selector is used to select all elements of a specific type in internal styles?
a. `.element`
b. *
c. `element`
d. `type: element`
Answer: c

9. Can internal styles override external styles?


a. Yes, always
b. No, external styles take precedence
c. It depends on the specificity of the selectors
d. Only if the internal styles are declared first
Answer: c

10. How can you include comments within internal styles?


a. `<!-- This is a comment -->`
b. `/* This is a comment */`
c. `// This is a comment`
d. `# This is a comment`
Answer: b

INLINE STYLES
1. How are inline styles applied in HTML elements?
a. Using the `<style>` tag in the `<head>` section
b. In a separate CSS file
c. Using the `style` attribute within the HTML tag
d. Inside a `<div>` tag
Answer: c

2. What is the primary drawback of using inline styles?


a. Limited styling options
b. Decreased page load time
c. Difficulty in maintenance
d. Inability to override styles
Answer: c

3. Which of the following is an example of an inline style declaration?


a. `<div style="color: red;">Content</div>`
b. `<div class="red-text">Content</div>`
c. `<div>#content { color: red; }</div>`
d. `<div><style>color: red;</style>Content</div>`
Answer: a

4. Can you use multiple inline styles in a single HTML element?


a. No, only one inline style is allowed
b. Yes, but it is not recommended
c. Yes, by separating them with commas
d. No, it will result in a syntax error
Answer: a

5. How do you include comments within inline styles?


a. `<!-- This is a comment -->`
b. `/* This is a comment */

`
c. `// This is a comment`
d. `# This is a comment`
Answer: NA (Inline styles do not support comments)

6. What is the syntax for applying multiple CSS properties in an inline style?
a. `style="property1: value1; property2: value2;"`
b. `style="property1: value1, property2: value2;"`
c. `style="property1= value1; property2= value2;"`
d. `style="{ property1: value1, property2: value2 }"`
Answer: a

7. Which HTML tag attribute is used to apply inline styles?


a. `css`
b. `style`
c. `class`
d. `format`
Answer: b
8. Can inline styles override internal and external styles?
a. Yes, always
b. No, external styles take precedence
c. It depends on the specificity of the selectors
d. Only if the inline styles are declared last
Answer: c

9. What is the purpose of the 'important' declaration in inline styles?


a. It makes the style more visually appealing
b. It prioritizes the style over other styles
c. It adds animation to the element
d. It increases the font size of the text
Answer: b

10. Which is the correct way to apply an inline style to set the background color to yellow?
a. `<div style="bg-color: yellow;">Content</div>`
b. `<div style="background-color: yellow;">Content</div>`
c. `<div style="color: yellow;">Content</div>`
d. `<div style="bgcolor: yellow;">Content</div>`
Answer: b

Feel free to use or modify these questions and answers as needed!


Certainly! Here are 10 multiple-choice questions (MCQs) with answers for each of the topics:
background styles, HTML, and commands in HTML.

BACKGROUND STYLES

1. Which CSS property is used to set the background color of an element?


a. `color`
b. `background-color`
c. `text-background`
d. `bgcolor`
Answer: b

2. What is the purpose of the 'background-image' property in CSS?


a. Change the font style of an element
b. Set a background color
c. Add an image as the background
d. Create a shadow behind an element
Answer: c

3. Which CSS property is used to control the positioning of the background image?
a. `background-position`
b. `image-position`
c. `position`
d. `background-align`
Answer: a

4. How can you repeat a background image both horizontally and vertically?
a. `background-repeat: both;`
b. `background-repeat: repeat;`
c. `background-repeat: horizontal vertical;`
d. `background-repeat: all;`
Answer: b

5. What does the 'background-attachment' property control in CSS?


a. Image brightness
b. Image size
c. Image position
d. Image scrolling behavior
Answer: d

6. Which CSS property is used to apply a background gradient?


a. `background-gradient`
b. `color-gradient`
c. `gradient`
d. `background-image: linear-gradient;`
Answer: d

7. What is the purpose of the 'background-size' property in CSS?


a. Adjust the size of the text
b. Set the size of the background image
c. Define the size of the element
d. Increase the padding of an element
Answer: b

8. How can you apply a background color with transparency in CSS?


a. `background-color: transparent;`
b. `color: rgba(255, 0, 0, 0.5);`
c. `background-opacity: 0.5;`
d. `opacity: 0.5;`
Answer: b

9. Which CSS property is used to control the blending mode of the background image?
a. `background-blend-mode`
b. `image-blend-mode`
c. `blend-mode`
d. `background-mode`
Answer: a

10. What is the purpose of the 'background-origin' property in CSS?


a. Specify where the background image starts
b. Define the origin of the element
c. Control the position of the background image
d. Determine the background's size
Answer: a

HTML
1. What does HTML stand for?
a. HyperText Markup Language
b. High-Level Text Management Language
c. Hyperlink and Text Management Language
d. Hyper Transferable Markup Language
Answer: a

2. Which HTML tag is used to create a hyperlink?


a. `<link>`
b. `<a>`
c. `<href>`
d. `<url>`
Answer: b

3. What is the purpose of the `<head>` element in HTML?


a. Define the main content of the page
b. Include metadata about the document
c. Set the background color of the page
d. Create a navigation menu
Answer: b

4. Which HTML tag is used to define the structure of an HTML document, including
headings, paragraphs, and lists?
a. `<body>`
b. `<content>`
c. `<structure>`
d. `<main>`
Answer: a

5. What is the correct way to create an ordered list in HTML?


a. `<ul>`
b. `<li>`
c. `<ol>`
d. `<dl>`
Answer: c

6. Which attribute is used to provide alternative text for an image in HTML?


a. `alt`
b. `text`
c. `description`
d. `image-alt`
Answer: a

7. In HTML, what is the purpose of the `<footer>` element?


a. Define a footer section for navigation
b. Specify the main content of the page
c. Provide contact information
d. Create a bottom margin for the page
Answer: a
8. What does the HTML acronym `<br>` stand for?
a. Break
b. Break Row
c. Break Rule
d. Breakline
Answer: a

9. Which HTML tag is used to embed a video in a web page?


a. `<embed>`
b. `<video>`
c. `<media>`
d. `<play>`
Answer: b

10. What is the purpose of the `<meta charset="UTF-8">` tag in HTML?


a. Set the character encoding of the document
b. Define the background color of the page
c. Specify the font size for the text
d. Create a meta description for search engines
Answer: a

COMMANDS IN HTML

1. Which HTML tag is used to define a hyperlink and its destination?


a. `<link>`
b. `<a>`
c. `<href>`
d. `<url>`
Answer: b

2. What is the purpose of the HTML `<div>` element?


a. Define a division or a section in the document
b. Display an inline block of text
c. Create a hyperlink
d. Insert an image
Answer: a

3. Which HTML tag is used to create an unordered list?


a. `<ul>`
b. `<ol>`
c. `<li>`
d. `<list>`
Answer: a

4. What is the role of the `<span>` tag in HTML?


a. Define a block of code
b. Format text as bold
c. Create a hyperlink
d. Apply styles to inline elements
Answer: d
5. What does the HTML attribute `target="_blank"` do in a hyperlink?
a. Opens the link in a new browser window
b. Sets the link as the homepage
c. Redirects to the link within the same window
d. Highlights the link
Answer: a

6. How can you create a line break within a paragraph in HTML?


a. Using the `<br>` tag
b. Adding extra spaces
c. Inserting a `<p>` tag
d. Applying the `<line>` tag
Answer: a

7. Which HTML tag is used to define an image in a webpage?


a. `<image>`
b. `<img>`
c. `<picture>`
d. `<photo>`
Answer: b

8. What is the function of the HTML `<iframe>` element?


a. Embed external content within a webpage
b. Define a block of code
c. Create a hyperlink
d. Insert an inline image
Answer: a

9. Which HTML tag is used to define the main content of a webpage?


a. `<main>`
b. `<body>`
c. `<content>`
d. `<section>`
Answer: a

10. What is the role of the HTML `<hr>` tag?


a. Create a hyperlink
b. Insert a horizontal line or rule
c. Define a header in a document
d. Highlight text
Answer: b

HTML TABLE LAYOUT

1. Which HTML tag is used to create a table?


a. `<table>`
b. `<tab>`
c. `<tbl>`
d. `<tabular>`
Answer: a

2. What does the `<th>` tag represent in an HTML table?


a. Table head
b. Table header
c. Table home
d. Table hold
Answer: b

3. Which attribute is used to define the number of columns in an HTML table?


a. `cols`
b. `columns`
c. `colspan`
d. `colcount`
Answer: c

4. How can you set the width of a table in HTML?


a. Using the `width` attribute in the `<table>` tag
b. Using the `table-width` property in CSS
c. Applying the `width` attribute to each `<td>` tag
d. By using the `table-layout` property in CSS
Answer: a

5. What does the `<tr>` tag represent in an HTML table?


a. Table row
b. Table resize
c. Table range
d. Table report
Answer: a

6. Which CSS property is used to add space between the table cell content and its borders?
a. `cell-spacing`
b. `padding`
c. `spacing`
d. `cell-padding`
Answer: b

7. How can you merge two or more cells in a row in HTML?


a. Using the `rowspan` attribute in the `<td>` tag
b. Applying the `merge` property in CSS
c. Adding the `colspan` attribute to the `<td>` tag
d. Using the `cell-merge` attribute in the `<tr>` tag
Answer: c

8. Which HTML tag is used to define a caption for an HTML table?


a. `<caption>`
b. `<title>`
c. `<head>`
d. `<label>`
Answer: a
9. What does the CSS property `border-collapse` do for an HTML table?
a. Adds a border around the entire table
b. Collapses the borders of adjacent cells into a single border
c. Increases the space between cells
d. Removes the borders from the table
Answer: b

10. Which attribute is used to provide a summary of the content and structure of an HTML
table?
a. `summary`
b. `description`
c. `table-summary`
d. `table-info`
Answer: a

HTML SYNTAX AND TAGS

1. What does HTML stand for?


a. HyperText Markup Language
b. High-Level Text Management Language
c. Hyperlink and Text Management Language
d. Hyper Transferable Markup Language
Answer: a

2. Which HTML tag is used to create a hyperlink?


a. `<link>`
b. `<a>`
c. `<href>`
d. `<url>`
Answer: b

3. What is the purpose of the `<head>` element in HTML?


a. Define the main content of the page
b. Include metadata about the document
c. Set the background color of the page
d. Create a navigation menu
Answer: b

4. Which HTML tag is used to define the structure of an HTML document, including
headings, paragraphs, and lists?
a. `<body>`
b. `<content>`
c. `<structure>`
d. `<main>`
Answer: a

5. What is the correct way to create an ordered list in HTML?


a. `<ul>`
b. `<li>`
c. `<ol>`
d. `<dl>`
Answer: c

6. Which attribute is used to provide alternative text for an image in HTML?


a. `alt`
b. `text`
c. `description`
d. `image-alt`
Answer: a

7. In HTML, what is the purpose of the `<footer>` element?


a. Define a footer section for navigation
b. Specify the main content of the page
c. Provide contact information
d. Create a bottom margin for the page
Answer: a

8. What does the HTML acronym `<br>` stand for?


a. Break
b. Break Row
c. Break Rule
d. Breakline
Answer: a

9. Which HTML tag is used to embed a video in a web page?


a. `<embed>`
b. `<video>`
c. `<media>`
d. `<play>`
Answer: b

10. What is the purpose of the `<meta charset="UTF-8">` tag in HTML?


a. Set the character encoding of the document
b. Define the background color of the page
c. Specify the font size for the text
d. Create a meta description for search engines
Answer: a

JAVA

1. Which of the following is not a primitive data type in Java?


a. int
b. float
c. boolean
d. class
Answer: d

2. What is the main purpose of the `public static void main(String[] args)` method in Java?
a. Define the entry point of the program
b. Declare variables in a class
c. Print output to the console
d. Perform mathematical operations
Answer: a

3. Which keyword is used to declare a constant variable in Java?


a. `var`
b. `final`
c. `const`
d. `static`
Answer: b

4. What is the correct syntax for a single-line comment in Java?


a. `// Comment text`
b. `/* Comment text */`
c. `-- Comment text`
d. `# Comment text`
Answer: a

5. What is the purpose of the `break` statement in Java?


a. Terminate a loop or switch statement
b. Define a new variable
c. Print a line of text to the console
d. Create a new object
Answer: a

6. Which of the following is an example of a loop statement in Java?


a. `if`
b. `for`
c. `switch`
d. `class

`
Answer: b

7. What is the concept of encapsulation in object-oriented programming?


a. Combining multiple classes into one
b. Hiding the implementation details and exposing only necessary functionalities
c. Creating objects from a class
d. Inheriting properties and behaviors from a parent class
Answer: b

8. Which method is called automatically when an object is created in Java?


a. `start()`
b. `init()`
c. `main()`
d. `constructor()`
Answer: d

9. What is the purpose of the `toString()` method in Java?


a. Convert an object to a string representation
b. Perform string concatenation
c. Parse a string into an integer
d. Split a string into an array
Answer: a

10. What does the term "polymorphism" refer to in Java?


a. The ability of a class to inherit from multiple classes
b. The ability of a method to have multiple parameters
c. The ability of a class to have multiple constructors
d. The ability of objects of different classes to be treated as objects of a common type
Answer: d

FEATURES OF JAVA

1. Which of the following is a feature of Java that contributes to its portability?


a. Platform-specific bytecode
b. Platform-independent bytecode
c. Native machine code
d. Exclusive reliance on hardware features
Answer: b

2. What is the primary advantage of Java's automatic memory management (garbage


collection)?
a. Increased execution speed
b. Reduced memory consumption
c. Elimination of syntax errors
d. Simplified exception handling
Answer: b

3. Which feature of Java allows a single class to provide multiple implementations of


methods with the same name?
a. Inheritance
b. Encapsulation
c. Polymorphism
d. Abstraction
Answer: c

4. What is the purpose of the 'final' keyword in Java?


a. To declare a constant variable
b. To mark a class as abstract
c. To indicate the end of a method
d. To prevent inheritance or method override
Answer: d

5. Which Java feature supports the creation of modular and reusable code units?
a. Inheritance
b. Encapsulation
c. Interfaces
d. Polymorphism
Answer: c

6. What is the significance of the 'try', 'catch', and 'finally' blocks in Java?
a. They define the main method in a Java program
b. They handle exceptions and ensure cleanup operations
c. They control the flow of execution within a loop
d. They are used for defining variables
Answer: b

7. Which feature of Java ensures that a subclass can provide a specific implementation for a
method defined in its superclass?
a. Inheritance
b. Encapsulation
c. Polymorphism
d. Abstraction
Answer: a

8. What is the purpose of the 'super' keyword in Java?


a. To access the superclass's variables and methods
b. To define a constant value
c. To declare an abstract method
d. To indicate the end of a class definition
Answer: a

9. Which feature of Java allows the creation of classes that share common characteristics
without using inheritance?
a. Abstract classes
b. Interfaces
c. Polymorphism
d. Encapsulation
Answer: b

10. What does the term "multithreading" refer to in the context of Java?
a. The ability of a class to have multiple constructors
b. The execution of multiple threads concurrently within a program
c. The process of optimizing bytecode for faster execution
d. The inheritance of properties and behaviors from a parent class
Answer: b

TRUNCATION

1. In the context of data representation, what does "truncation" refer to?


a. Rounding a number to the nearest integer
b. Removing decimal places from a number without rounding
c. Representing negative numbers
d. Converting binary to decimal
Answer: b

2. What is the result of truncating the decimal value 7.987 to an integer?


a. 7
b. 8
c. 7.5
d. 8.5
Answer: a

3. Which mathematical operation is often associated with truncation?


a. Addition
b. Subtraction
c. Division
d. Multiplication
Answer: c

4. When truncating a negative decimal number, how is the process typically handled?
a. The integer part is rounded up
b. The integer part is rounded down
c. The decimal part is rounded up
d. The decimal part is rounded down
Answer: b

5. What is the primary limitation of truncation when converting real numbers to integers?
a. Loss of precision
b. Overflow errors
c. Underflow errors
d. Rounding errors
Answer: a

6. Which programming language function is commonly used for truncation in many contexts?
a. `ceil()`
b. `floor()`
c. `round()`
d. `trunc()`
Answer: d

7. In the context of computer systems, what is the purpose of truncating data?


a. To reduce the size of data storage
b. To improve data accuracy
c. To increase the precision of data
d. To simplify data representation
Answer: a

8. What happens when truncating a floating-point number towards zero?


a. The decimal part is rounded up
b. The decimal part is rounded down
c. The integer part is rounded up
d. The integer part is rounded down
Answer: b

9. How does truncation differ from rounding in mathematical operations?


a. Truncation always rounds up, while rounding can round up or down.
b. Truncation removes decimal places without rounding, while rounding adjusts decimal
places.
c. Truncation is used only for negative numbers, while rounding is used for positive
numbers.
d. Truncation is more precise than rounding in all cases.
Answer: b

10. Which of the following statements about truncation is true?


a. Truncation always results in a larger value.
b. Truncation is equivalent to rounding.
c. Truncation is commonly used in financial calculations.
d. Truncation is only applicable to integer values.
Answer: c

INTERFACES

1. In Java, what is an interface?


a. A class that cannot be instantiated
b. A collection of methods and variables
c. A programming language feature for multiple inheritance
d. A graphical user interface element
Answer: b

2. What is the purpose of an interface in Java?


a. To define a concrete implementation of a class
b. To provide a blueprint for a class with abstract methods
c. To create an instance of a class
d. To encapsulate data within a class
Answer: b

3. Which keyword is used to declare an interface in Java?


a. `interface`
b. `class`
c. `implements`
d. `abstract`
Answer: a

4. Can an interface in Java have method implementations?


a. Yes, always
b. No, never
c. Yes, but only for default methods
d. Yes, but only for abstract methods
Answer: c

5. How is multiple inheritance achieved through interfaces in Java?


a. By extending multiple classes
b. By implementing multiple interfaces
c. By using the `extends` keyword in interface declaration
d. By using the `implements` keyword in class declaration
Answer: b
6. What is the difference between an interface and an abstract class in Java?
a. An interface cannot have variables, while an abstract class can.
b. An abstract class cannot have abstract methods, while an interface can.
c. An abstract class can have method implementations, while an interface cannot.
d. An interface cannot be extended, while an abstract class can.
Answer: c

7. In Java, can a class implement multiple interfaces?


a. Yes, but only if the interfaces have the same methods.
b. No, a class can implement only one interface.
c. Yes, a class can implement multiple interfaces.
d. No, it depends on the class hierarchy.
Answer: c

8. Which of the following is a valid interface declaration in Java?


a. `public class MyInterface { }`
b. `interface MyInterface { }`
c. `abstract interface MyInterface { }`
d. `interface abstract MyInterface { }`
Answer: b

9. What is the purpose of the `default` keyword in interface methods in Java?


a. To specify that the method is optional for implementing classes
b. To define a method with a default implementation
c. To indicate that the method is a reserved keyword
d. To declare a method as the default entry point for the interface
Answer: b

10. Can an interface extend another interface in Java?


a. Yes, using the `extends` keyword
b. Yes, using the `implements` keyword
c. No, interfaces cannot extend other interfaces
d. No, interfaces can only extend classes
Answer: a

EXCEPTION HANDLING

1. What is the purpose of exception handling in programming?


a. To create intentional errors
b. To avoid writing error messages
c. To handle unexpected runtime errors
d. To increase program speed
Answer: c

2. Which keyword is used to throw an exception in Java?


a. `catch`
b. `throw`
c. `try`
d. `finally`
Answer: b

3. What is the role of the `finally` block in exception handling?


a. It is used to catch exceptions.
b. It is executed regardless of whether an exception occurs or not.
c. It is used to declare variables.
d. It is executed only if an exception occurs.
Answer: b

4. What is the purpose of the `try` block in exception handling?


a. To declare variables
b. To catch exceptions
c. To execute a block of code that might throw exceptions
d. To finally handle an exception
Answer: c

5. Which of the following is NOT part of the Java exception hierarchy?


a. `Error`
b. `RuntimeException`
c. `Exception`
d. `AbortException`
Answer: d

6. What happens if an exception is not caught by any `catch` block?


a. It is automatically rethrown.
b. It is ignored, and the program continues execution.
c. It triggers a compilation error.
d. It causes the program to terminate abruptly.
Answer: d

7. Which method is used to retrieve the exception message in Java?


a. `getMessage()`
b. `getException()`
c. `catchException()`
d. `retrieveMessage()`
Answer: a

8. In Java, what is the purpose of the `throws` keyword in a method signature?


a. To declare that the method can throw multiple exceptions
b. To indicate the method has caught an exception
c. To specify the type of exception that the method may throw
d. To prevent the method from throwing any exceptions
Answer: c

9. Which block can be omitted when using a `try-catch` statement in Java?


a. `try`
b. `catch`
c. `finally`
d. All blocks are mandatory.
Answer: c
10. What is the purpose of the `printStackTrace()` method in Java exception handling?
a. It prints the error message to the console.
b. It prints the stack trace of the exception to the console.
c. It handles the exception without printing anything.
d. It prints the exception type only.
Answer: b

ACCESS MODIFIERS

1. In Java, what is the default access modifier for class members if no modifier is specified?
a. `public`
b. `protected`
c. `private`
d. Package-private (default)
Answer: d

2. Which access modifier allows a class member to be accessed within the same class,
package, and subclasses?
a. `public`
b. `protected`
c. `private`
d. Package-private
Answer: b

3. In Java, what is the access level of a member with the `private` modifier?
a. Accessible only within the same class
b. Accessible within the same class and package
c. Accessible within the same class, package, and subclasses
d. Accessible from any class
Answer: a

4. What is the purpose of the `protected` access modifier in Java?


a. To make a member accessible only within its own class
b. To make a member accessible within the same package and subclasses
c. To make a member accessible only within the same package
d. To make a member accessible from any class
Answer: b

5. Which access modifier allows a class member to be accessed from any class in any
package?
a. `public`
b. `protected`
c. `private`
d. Package-private
Answer: a

6. In Java, what is the default access modifier for an interface?


a. `public`
b. `protected`
c. `private`
d. Package-private
Answer: a

7. Which access modifier restricts access to the same package only in Java?
a. `public`
b. `protected`
c. `private`
d. Package-private
Answer: d

8. What is the purpose of the `default` keyword in Java access modifiers?


a. It is used as an access modifier.
b. It represents the absence of an access modifier.
c. It provides access to all classes.
d. It is a synonym for `public`.
Answer: b

9. Which access modifier is appropriate for a method that should only be accessible within
the same package?
a. `public`
b. `protected`
c. `private`
d. Package-private
Answer: d

10. In Java, which access modifier allows a subclass in a different package to access a
protected member of its superclass?
a. `public`
b. `protected`
c. `private`
d. Package-private
Answer: b

FINAL KEYWORD

1. In Java, what does the `final` keyword signify when used with a class declaration?
a. The class cannot be instantiated.
b. The class cannot be extended by other classes.
c. The class cannot have any methods.
d. The class cannot have any fields.
Answer: b

2. What is the purpose of the `final` keyword when applied to a method in Java?
a. The method cannot be called.
b. The method cannot be overridden by subclasses.
c. The method cannot be declared as static.
d. The method cannot have any parameters.
Answer: b
3. When used with a variable in Java, what does the `final` keyword indicate?
a. The variable cannot be changed once assigned a value.
b. The variable must be initialized within the constructor.
c. The variable is shared among multiple instances of the class.
d. The variable is automatically assigned a default value.
Answer: a

4. In Java, can a constructor be marked as `final`?


a. Yes, always
b. No, never
c. Yes, but only if it has parameters
d. Yes, but only if it's a static constructor
Answer: b

5. When applied to a class method, what does the `final` keyword prevent?
a. The method from being called
b. The method from being overridden by subclasses
c. The method from accessing other methods
d. The method from having any parameters
Answer: b

6. In Java, can a `final` variable be reassigned a new value after initialization?


a. Yes, always
b. No, never
c. Yes, but only within the same package
d. Yes, but only within the same class
Answer: b

7. What is the significance of the `final` keyword in the context of method parameters in
Java?
a. It prevents the method from having parameters.
b. It ensures that the parameters are always assigned a value.
c. It indicates that the parameters are passed by reference.
d. It allows the method to be called without any arguments.
Answer: b

8. When applied to a class, what does the `final` keyword indicate about the class members?
a. The class members cannot be accessed.
b. The class members are all static.
c. The class members are all private.
d. The class members cannot be overridden in subclasses.
Answer: d

9. What happens if an attempt is made to extend a class marked as `final` in Java?


a. It results in a compilation error.
b. It is allowed, and the subclass inherits all members.
c. It is allowed, but the subclass cannot override any methods.
d. It results in a runtime error.
Answer: a
10. In Java, what is the purpose of the `final` keyword when applied to a block of code?
a. It prevents the block of code from being executed.
b. It ensures that the block of code is executed only once.
c. It indicates that the block of code is synchronized.
d. It has no specific purpose for a block of code.
Answer: d

`FINALLY` IN EXCEPTION HANDLING

1. What is the purpose of the `finally` block in Java exception handling?


a. It is executed when an exception is caught.
b. It is executed before the `try` block.
c. It is executed regardless of whether an exception occurs or not.
d. It is used to declare variables.
Answer: c

2. In a `try-catch-finally` block, which block is optional?


a. `try`
b. `catch`
c. `finally`
d. Both `try` and `catch`
Answer: c

3. Can a `finally` block be used without a `try` block in Java?


a. Yes, always
b. No, never
c. Yes, but it won't have any effect
d. Yes, but it will result in a compilation error
Answer: c

4. What happens if an exception occurs in both the `try` and `catch` blocks, and there is a
`finally` block?
a. The `finally` block is skipped.
b. The `finally` block is executed before the `catch` block.
c. The `finally` block is executed after the `catch` block.
d. The `finally` block is executed before the `try` block.
Answer: c

5. Which of the following statements about the `finally` block is true?


a. It can be omitted in exception handling.
b. It is always required in exception handling.
c. It is executed only if an exception occurs.
d. It is executed only if an exception is not caught.
Answer: b

6. What is the primary purpose of the `finally` block?


a. To handle exceptions
b. To declare variables
c. To ensure cleanup operations are executed
d. To throw exceptions
Answer: c

7. Can a `finally` block modify the value of a variable defined in the `try` block?
a. Yes, always
b. No, never
c. Yes, but only if the variable is declared as `final`
d. Yes, but only if the variable is declared as `static`
Answer: a

8. In what scenario might the `finally` block not be executed?


a. When an exception is caught in the `catch` block
b. When an exception is not caught
c. When the program encounters a compilation error
d. When the `finally` block is omitted
Answer: c

9. What is the significance of the `return` statement in a `finally` block?


a. It is not allowed in a `finally` block.
b. It terminates the program execution immediately.
c. It overrides any previous return statements in the method.
d. It does not affect the return value of the method.
Answer: c

10. When might it be appropriate to use a `finally` block without a `catch` block?
a. When no exceptions are expected
b. When handling checked exceptions only
c. When cleanup operations are necessary, regardless of exceptions
d. When handling unchecked exceptions only
Answer: c

RECURSION

1. What is recursion in programming?


a. A loop that repeats a set of instructions
b. A function that calls itself
c. A process of eliminating runtime errors
d. A type of data structure
Answer: b

2. In recursive functions, what is the base case?


a. The case where the function returns a value
b. The case where the function calls itself
c. The case where the function terminates without further recursion
d. The case where the function encounters an exception
Answer: c

3. What is the main advantage of using recursion in programming?


a. It improves code readability.
b. It reduces memory usage.
c. It simplifies the logic of certain problems.
d. It speeds up program execution.
Answer: c

4. What is the term for the process where a function calls itself in a recursive manner?
a. Looping
b. Iteration
c. Recursing
d. Tail calling
Answer: c

5. In recursive functions, what is the stack used for?


a. To store loop counters
b. To store local variables
c. To manage function calls and returns
d. To prevent infinite recursion
Answer: c

6. What is the potential drawback of using recursion in programming?


a. Increased code complexity
b. Improved performance
c. Stack overflow errors
d. Reduced memory usage
Answer: c

7. Which programming languages support recursion?


a. Only low-level languages
b. Only functional languages
c. Only object-oriented languages
d. Most modern programming languages
Answer: d

8. What is the significance of the "Call Stack" in recursion?


a. It prevents the function from calling itself.
b. It stores the return addresses of recursive calls.
c. It limits the number of recursive calls.
d. It enforces a specific order of execution.
Answer: b

9. In a recursive function, what is the role of the "Stack Overflow" error?


a. To indicate that the function is executing correctly.
b. To prevent the function from calling itself indefinitely.
c. To handle memory allocation errors.
d. To signal that the call stack has reached its limit.
Answer: d

10. When should recursion be preferred over iteration in programming?


a. When the problem can be easily solved with a loop.
b. When memory usage is a critical concern.
c. When the problem can be naturally decomposed into smaller subproblems.
d. When performance is the top priority.
Answer: c

FEATURES OF DBMS

1. What is the primary function of a Database Management System (DBMS)?


a. To manage the hardware components of a computer
b. To create graphical user interfaces
c. To organize and control access to a database
d. To write programs in low-level languages
Answer: c

2. Which of the following is a feature of a DBMS that ensures data consistency and integrity?
a. Concurrency control
b. Data redundancy
c. Data isolation
d. Data mining
Answer: a

3.What is the purpose of a DBMS in managing data security?


a. To hide data from authorized users
b. To restrict access to sensitive data
c. To duplicate data for backup purposes
d. To limit the number of users in the database
Answer: b

4. Which feature of a DBMS allows multiple users to access and modify the data
concurrently?
a. Data abstraction
b. Data normalization
c. Concurrency control
d. Data replication
Answer: c

5. In the context of a DBMS, what does "ACID" stand for?


a. Atomicity, Consistency, Isolation, Durability
b. Association, Compatibility, Integration, Design
c. Accessibility, Compatibility, Integrity, Durability
d. Atomicity, Coherence, Integration, Durability
Answer: a

6. Which feature of a DBMS allows users to define the structure of the data they want to
store?
a. Data manipulation
b. Data normalization
c. Data definition
d. Data abstraction
Answer: c

7. What is the significance of normalization in a DBMS?


a. It reduces data redundancy and improves data integrity.
b. It increases data redundancy and simplifies data retrieval.
c. It limits the number of concurrent users.
d. It defines the structure of the database.
Answer: a

8. Which feature of a DBMS allows users to retrieve and manipulate data using a query
language?
a. Data abstraction
b. Data definition
c. Data manipulation
d. Data independence
Answer: c

9. In a DBMS, what is the purpose of the "Data Dictionary"?


a. To store user passwords
b. To manage database transactions
c. To store metadata about the database
d. To create graphical user interfaces
Answer: c

10. Which feature of a DBMS ensures that changes made to the database are permanent and
survive system failures?
a. Atomicity
b. Consistency
c. Durability
d. Isolation
Answer: c

COMPONENTS OF DATABASE

1. What is the primary purpose of a database in the context of information management?


a. To store and manage hardware components
b. To organize and control access to data
c. To create graphical user interfaces
d. To execute low-level programming instructions
Answer: b

2. Which component of a database stores a collection of related records?


a. Query
b. Table
c. Attribute
d. Form
Answer: b

3. In a relational database, what is the role of a "relation"?


a. It represents a data entry form.
b. It defines the structure of a database.
c. It stores a collection of related records.
d. It executes SQL queries.
Answer: c
4. What is the function of the "DBMS" (Database Management System) among the
components of a database?
a. To store data in tables
b. To organize data into relationships
c. To provide a user interface for data entry
d. To manage and control the database
Answer: d

5. Which component of a database is responsible for defining the structure of the data and
relationships?
a. Data dictionary
b. Query processor
c. Transaction manager
d. Form designer
Answer: a

6. What is the purpose of a "view" in a database?


a. To physically store data
b. To provide a virtual representation of data based on specific criteria
c. To enforce data integrity constraints
d. To create relationships between tables
Answer: b

7. Which component of a database system is responsible for enforcing data integrity


constraints?
a. Query optimizer
b. Index manager
c. Transaction manager
d. Constraint enforcer
Answer: c

8. What is the significance of a "transaction" in a database?


a. It represents a collection of related records.
b. It defines the structure of the database.
c. It is a sequence of one or more SQL statements executed as a single unit.
d. It is a visual representation of database relationships.
Answer: c

9. Which component of a database system ensures that changes made to the database are
permanent and survive system failures?
a. Query processor
b. Recovery manager
c. Data dictionary
d. Index manager
Answer: b

10. In a database, what is the purpose of a "query language"?


a. To define the structure of the database
b. To store and manage data
c. To manipulate and retrieve data
d. To enforce data integrity constraints
Answer: c

PRIMARY KEY

1. What is the primary purpose of a "primary key" in a database table?


a. To store large amounts of data
b. To uniquely identify each record in the table
c. To define relationships between tables
d. To sort records in ascending order
Answer: b

2. In a relational database, what characteristic must a primary key possess?


a. It can be null.
b. It must be unique for each record.
c. It can be duplicated within the table.
d. It must be a composite key.
Answer: b

3. Which SQL keyword is used to define a primary key when creating a table?
a. PRIMARY
b. IDENTITY
c. UNIQUE
d. KEY
Answer: a

4. What happens if a record in a table has a null value in its primary key column?
a. It violates data integrity constraints.
b. It is automatically assigned a default value.
c. It is treated as a wildcard value.
d. It does not affect the primary key constraint.
Answer: a

5. In a database table, can a primary key consist of multiple columns?


a. Yes, always
b. No, never
c. Yes, but only if all columns are numeric
d. Yes, but only if one column is numeric
Answer: a

6. What is the purpose of using an "auto-increment" feature for a primary key column?
a. To automatically generate random primary key values
b. To automatically assign default values to the primary key
c. To automatically increment the primary key value for each new record
d. To automatically enforce referential integrity
Answer: c

7. How does a primary key contribute to maintaining referential integrity between tables?
a. By allowing duplicate values in the foreign key column
b. By preventing updates to the primary key values
c. By ensuring that each foreign key references a unique primary key
d. By allowing null values in the foreign key column
Answer: c

8. Which statement about the primary key is true in the context of database normalization?
a. It encourages redundancy in data storage.
b. It facilitates the removal of duplicate records.
c. It is not related to data organization.
d. It is optional for each table.
Answer: b

9. In a database, can a primary key value be modified after it has been assigned to a record?
a. Yes, always
b. No, never
c. Yes, but only if the primary key is a composite key
d. Yes, but only if the primary key is an auto-incremented column
Answer: b

10. What is the significance of the "foreign key" in relation to a primary key in a relational
database?
a. It is a backup key for the primary key.
b. It is used to establish relationships between tables.
c. It is an alternative to the primary key.
d. It is used to sort records based on primary key values.
Answer: b

FOREIGN KEY

1. What is the primary purpose of a "foreign key" in a relational database?


a. To uniquely identify each record in a table
b. To define relationships between tables
c. To enforce data integrity constraints
d. To organize and control access to data
Answer: b

2. In a database, how does a foreign key relate to a primary key in another table?
a. It must have the same name as the primary key.
b. It must reference a unique primary key in another table.
c. It must be of the same data type as the primary key.
d. It must be larger than the primary key.
Answer: b

3. Which SQL clause is used to define a foreign key when creating a table?
a. LINK
b. RELATE
c. FOREIGN
d. REFERENCES
Answer: d
4. What happens if a record in a table has a foreign key value that does not match any
primary key in the referenced table?
a. It is automatically updated to match the primary key.
b. It violates referential integrity constraints.
c. It is automatically assigned a default value.
d. It is treated as a null value.
Answer: b

5. In a database, can a table have multiple foreign keys referencing different tables?
a. Yes, always
b. No, never
c. Yes, but only if the foreign keys have the same name
d. Yes, but only if the foreign keys reference the same primary key
Answer: a

6. What is the significance of the "CASCADE" option in the context of foreign key
constraints?
a. It allows foreign key values to be null.
b. It automatically updates or deletes related records in the referenced table.
c. It enforces that foreign keys cannot be modified.
d. It allows duplicate foreign key values.
Answer: b

7. How does a foreign key contribute to maintaining referential integrity between tables?
a. By preventing updates to the foreign key values
b. By allowing duplicate values in the referenced table
c. By ensuring that each foreign key references a unique primary key
d. By allowing null values in the foreign key column
Answer: c

8. Can a foreign key reference a column that is not a primary key in the referenced table?
a. Yes, always
b. No, never
c. Yes, but only if the referenced column is unique
d. Yes, but only if the referenced column is an auto-incremented column
Answer: c

9. What is the purpose of the "NO ACTION" option in the context of foreign key constraints?
a. It allows the foreign key to be null.
b. It automatically updates or deletes related records in the referenced table.
c. It prevents modifications to the referenced primary key.
d. It allows updates or deletes only if they do not affect referential integrity.
Answer: d

10. In a database, what role does a foreign key play in relational database design?
a. It defines the structure of a database.
b. It ensures that data is stored without redundancy.
c. It establishes relationships between tables.
d. It facilitates the creation of views.
Answer: c

You might also like