Chapter-1 Programming Fundamentals


1. How many types of access specifiers are there in Java?

a. 2

b. 3

c. 4

d. 5

✅c. 4 (public, private, protected, and default (no modifier))


2. Which access specifier allows access from anywhere in the program?

a. private

b. protected

c. public

d. default

✅c. public


3. Which access specifier restricts access to only within the same class?

a. private

b. protected

c. public

d. default

✅a. private


4. If no access specifier is mentioned, which access level is applied?

a. private

b. protected

c. public

d. default

✅d. default


5. Which access specifier allows access within the same package and to subclasses in other packages?

a. private

b. protected

c. public

d. default

✅b. protected


6. Which of the following statements about the private access specifier is true?

a. Private members are accessible in subclasses

b. Private members are accessible within the same package

c. Private members are accessible only within the same class

d. Private members are accessible from any class

✅c. Private members are accessible only within the same class


7. Which access specifier prevents a class from being inherited?

a. protected

b. private

c. final

d. default

✅c. final (Although final is a keyword, not an access specifier, it prevents inheritance)


8. Which access specifier allows access within the same package only?

a. protected

b. private

c. default

d. public

✅c. default


9. Which access specifier provides the highest level of security to data members?

a. protected

b. private

c. default

d. public

✅b. private


10. Can a private method be accessed outside its class using an object?

a. Yes

b. No

c. Only if it's in the same package

d. Only if it’s a static method

✅b. No


11. What is inheritance in Java?

a. A process of creating multiple classes from a single class

b. A process where one class acquires the properties and behaviors of another class

c. A process of hiding data

d. A process of running multiple threads

✅b. A process where one class acquires the properties and behaviors of another class


12. Which keyword is used to inherit a class in Java?

a. implements

b. extends

c. inherits

d. super

✅b. extends


13. Which type of inheritance is not supported in Java?

a. Single Inheritance

b. Multilevel Inheritance

c. Multiple Inheritance using classes

d. Hierarchical Inheritance

✅c. Multiple Inheritance using classes


14. If class B extends class A, which statement is correct?

a. B is the parent class, A is the child class

b. A is the parent class, B is the child class

c. Both A and B are child classes

d. None of the above

✅b. A is the parent class, B is the child class


15. In Java, can a class extend multiple classes?

a. Yes

b. No

c. Only if they are abstract

d. Only if they are interfaces

✅b. No (Java does not support multiple inheritance using classes)


16.Which type of inheritance is demonstrated in the following code?
class A { }
class B extends A { }
class C extends B { }

a. Single Inheritance

b. Multiple Inheritance

c. Multilevel Inheritance

d. Hierarchical Inheritance

✅c. Multilevel Inheritance


17. What is method overriding in Java?

a. Defining multiple methods with the same name in the same class

b. Defining a method in the subclass with the same signature as in the superclass

c. Using the final keyword to modify a method

d. Declaring a method private

✅b. Defining a method in the subclass with the same signature as in the superclass


18. Which method is used to find the length of a string in Java?

a. size()

b. getSize()

c. count()

d. length()

✅d. length(


19. Which method converts all characters of a string to uppercase?

a. toUpper()

b. upperCase()

c. toUpperCase()

d. makeUpperCase()

✅c. toUpperCase()


20. Which method extracts a portion of a string?

a. extract()

b. subString()

c. split()

d. substring()

✅d. substring()


21. Which method removes whitespace from both ends of a string?

a. strip()

b. trim()

c. removeSpaces()

d. clean()

✅b. trim()


22. Which method is used to concatenate two strings?

a. append()

b. join()

c. merge()

d. concat()

✅d. concat(


23. Which method returns the character at a specified index in a string?

a. getChar()

b. charAt()

c. findChar()

d. characterAt()

✅b. charAt()


24. What is the output of "hello".toUpperCase()?

a. HELLO

b. Hello

c. hello

d. hELLO

✅a. HELLO


25. What is the primary benefit of using inheritance in Java?

a. Increased program size

b. Slower execution speed

c. Code reusability

d. Higher memory consumption

✅c. Code reusability


26. Which method is used to find the square root of a number?

a. sqrt()

b. squareRoot()

c. sqr()

d. root()

✅a. sqrt()


27. What will Math.pow(2, 3) return?

a. 6

b. 8

c. 16

d. 4

✅b. 8


28. What is the output of Math.round(4.6)?

a. 4

b. 5

c. 4.5

d. 6

✅b. 5


29. Which method returns the smaller of two numbers?

a. min()

b. max()

c. floor()

d. abs()

✅a. min()


30. What is the output of Math.max(10, 20)?

a. 10

b. 20

c. 30

d. 15

✅b. 20


31.What does JDBC stand for?

a. Java Data Components

b. Java Development Connector

c. Java Database Connectivity

d. Java Direct Connection

✅c. Java Database Connectivity


32.Which package contains JDBC classes?

a. java.jdbc

b. java.sql

c. javax.jdbc

d. java.database

✅b. java.sql


33.Which method is used to load the JDBC driver?

a. DriverManager.loadDriver()

b. Class.forName()

c. loadDriver()

d. Driver.load()

✅b. Class.forName(


34.Which class provides the methods to connect to a database?

a. Connection

b. Statement

c. Driver

d. ResultSet

✅a. Connection


35.Which class manages a list of database drivers?

a. Statement

b. Connection

c. ResultSet

d. DriverManager

✅d. DriverManager


36.What is the correct order to use JDBC API?

a. Connect > Load Driver > Execute Query > Close

b. Load Driver > Connect > Execute Query > Close

c. Load Driver > Execute Query > Connect > Close

d. Execute Query > Connect > Load Driver > Close

✅b. Load Driver > Connect > Execute Query > Close


37.What does the executeQuery() method of Statement return?

a. Connection

b. ResultSet

c. ResultSetMetaData

d. Boolean

✅b. ResultSet


38.Which method is used to execute insert, update, or delete statements?

a. run()

b. execute()

c. executeQuery()

d. executeUpdate()

✅d. executeUpdate(


39.Which JDBC driver type translates JDBC calls into ODBC calls?

a. Type-1

b. Type-2

c. Type-3

d. Type-4

✅a. Type-1


40.Which driver type is known as a "Thin driver"?

a. Type-1

b. Type-2

c. Type-3

d. Type-4

✅d. Type-4


41.What does ODBC stand for?

a. Open Data Backup Connector

b. Object DataBase Control

c. Oracle Database Connectivity

d. Open Database Connectivity

✅d. Open Database Connectivity


42.What does the ResultSet interface do?

a. Creates a connection

b. Holds data retrieved from a database

c. Executes SQL commands

d. Logs SQL errors

✅b. Holds data retrieved from a database


43.How do you retrieve a string value from ResultSet?

a. getVal()

b. getText()

c. getString()

d. fetchString()

✅c. getString()


44.What does rs.next() return if no more rows?

a. true

b. false

c. null

d. 0

✅b. false


45.What method is used to retrieve an integer value from ResultSet?

a. getInteger()

b. getInt()

c. fetchInt()

d. retrieveInt()

✅b. getInt()


46.Which method of ResultSet moves the cursor to the last row?

a. moveToLast()

b. last()

c. cursorToLast()

d. end()

✅b. last()


47.Which method closes the database connection?

a. shutdown()

b. close()

c. terminate()

d. disconnect()

✅b. close()


48.Which of these is not a type of JDBC driver?

a. JDBC-ODBC Bridge driver

b. Native-API driver

c. Server driver

d. Middleware driver

✅c. Server driver


49.Which of the following is not part of the JDBC API?

a. DriverManager

b. Connection

c. JDBCBridge

d. ResultSet

✅c. JDBCBridge


50.What happens if you forget to close JDBC resources?

a. Nothing

b. Memory leak and locked DB resources

c. App stops working

d. Compilation error

✅b. Memory leak and locked DB resources


Chapter-2 HTML based web pages covering basic tags


1. What does HTML stand for?

a. HyperText Markup Language

b. HighText Markup Language

c. Hyper Tool Markup Language

d. None of the above

a. HyperText Markup Language


2. Which HTML tag is used to insert an image?

a. img

b. image

c. src

d. picture

a. img


3. Which HTML attribute is used to specify the URL of an image?

a. href

b. src

c. alt

d. link

b. src


4. Which tag is used to define a hyperlink in HTML?

a. hyperlink

b. link

c. href

d. a

d. a


5. Which tag is used to create a table in HTML?

a. tbody

b. table

c. tr

d. td

b. table


6. Which HTML tag is used to create a paragraph?

a. para

b. p

c. paragraph

d. text

b. p


7. Which HTML tag is used to define an unordered list?

a. ol

b. ul

c. list

d. ulist

b. ul


8. Which tag is used to define a list item in an ordered or unordered list?

a. li

b. item

c. list

d. ol

a. li

9. What is the purpose of the head tag in HTML?

a. To define the main content of the page

b. To include metadata and links to external files like CSS

c. To display the title of the page

d. None of the above

b. To include metadata and links to external files like CSS

10. Which attribute is used to define the style of an element?

a. style

b. class

c. id

d. type

a. style

11. How do you add a comment in HTML?

a. // This is a comment

b.

c. /* This is a comment */

d. # This is a comment

b.

12. What is the purpose of the title tag in HTML?

a. To display a title in a table

b. To define the header of the webpage

c. To set the title of the webpage

d. To create the title of a list item

c. To set the title of the webpage

13. Which tag is used to define a form in HTML?

a. input

b. form

c. textarea

d. button

b. form

14. What is the correct way to create a checkbox in HTML?

a. checkbox

b. input type="checkbox"

c. input type="radio"

d. check

b. input type="checkbox"

15. How do you make a numbered list in HTML?

a. ul

b. ol

c. nl

d. li

b. ol

16. What is the default value of the type attribute in an input tag?

a. password

b. text

c. checkbox

d. radio

b. text

17. Which tag is used to display the largest heading in HTML?

a. h4

b. h1

c. h2

d. h3

b. h1

18. What does the br tag do in HTML?

a. Adds a horizontal line

b. Breaks the text and moves it to the next line

c. Adds a space between paragraphs

d. Adds a line break and changes the text color

b. Breaks the text and moves it to the next line

19. How do you define the language of an HTML document?

a. html lang="en"

b. html language="en"

c. html lang="english"

d. html lang="us"

a. html lang="en"

20. Which tag is used to include an external stylesheet in HTML?

a. style

b. script

c. link

d. css

c. link

21. What is the function of the alt attribute in an image tag?

a. To define the image width

b. To define the image source

c. To display alternative text when the image is not loaded

d. To define the image height

c. To display alternative text when the image is not loaded

22. How do you create a radio button in HTML?

a. radio

b. input type="button"

c. input type="checkbox"

d. input type="radio"

d. input type="radio"

23. Which attribute is used to provide a unique identifier to an HTML element?

a. class

b. id

c. type

d. style

b. id

24. How can you add a background color to a webpage in HTML?

a. background-color: #FFFFFF;

b. background color="red"

c. background-color="#FFFFFF"

d. body background="red"

a. background-color: #FFFFFF;

25.Which tag is used to make a text bold in HTML?

a. i

b. b

c. bold

d. bld

b. b

26. Which tag is used to create a dropdown list in HTML?

a. select

b. option

c. list

d. dropdown

a. select

27. How do you specify the action when a form is submitted in HTML?

a. action="submit"

b. method="submit"

c. action="URL"

d. form-action="submit"

c. action="URL"

28. Which tag is used to define a list of options in a dropdown?

a. li

b. option

c. dropdown

d. list

b. option

29. How do you define a clickable button in HTML?

a. button

b. input type="button"

c. click

d. Both a and b

d. Both a and b

30. Which tag is used to display a list of items vertically in HTML?

a. ol

b. ul

c. li

d. both a and b

d. both a and b

31. How do you add a background image in HTML?

a. background-image="image.jpg"

b. img src="image.jpg" background

c. body background="image.jpg"

d. None of the above

c. body background="image.jpg"

32. How do you define a table row in HTML?

a. td

b. tr

c. th

d. table-row

b. tr

33. Which tag is used to define a table header cell in HTML?

a. td

b. tr

c. th

d. header

c. th

34. Which attribute in the "a" tag specifies the destination of a link?

a. source

b. link

c. href

d. path

c. href

35. Which HTML element is used for a definition list?

a. dl

b. dt

c. dd

d. All of the above

d. All of the above

36. Which tag is used to create a horizontal rule (line) in HTML?

a. line

b. hr

c. rule

d. horizontal

b. hr

37. Which attribute of the "input" tag specifies the type of input control to display?

a. value

b. type

c. placeholder

d. input-type

a. value

38. What does the "form" tag do in HTML?

a. Defines a form to accept user input

b. Defines a button for submission

c. Defines a text input field

d. Defines the layout of the page

a. Defines a form to accept user input

39. How do you group related radio buttons together in HTML?

a. Using the group attribute

b. Using the name attribute

c. Using the value attribute

d. Using the form attribute

b. Using the name attribute

40. Which of the following tags defines an image in HTML?

a. image

b. img

c. src

d. picture

b. img

41. What is the purpose of the lang attribute in HTML?

a. Specifies the text direction

b. Specifies the language of the content

c. Specifies the font type

d. Specifies the character encoding

b. Specifies the language of the content

42. Which of the following tags is used to define a definition term in a definition list?

a. dt

b. dd

c. dl

d. term

a. dt

43. What tag is used to create a form control for entering a single line of text?

a. textarea

b. input

c. button

d. label

b. input

44. Which tag is used to define a definition description in a definition list?

a. dt

b. dd

c. dl

d. desc

b. dd

45. Which of the following HTML elements is used to display a table cell?

a. cell

b. td

c. tr

d. th

b. td