Tag: web technology

Questions Related to web technology

Constants are declared using the keyword

  1. Constant

  2. Const

  3. Consta

  4. Fixed


Correct Option: B

Which keyword can protect a class in a package from accessibility by the classes outside the package?

  1. private

  2. b.final

  3. c.protected

  4. d.don't use any keyword at all (make it default)


Correct Option: D

AI Explanation

To answer this question, you need to understand the access modifiers in Java.

The access modifiers in Java are used to control the visibility and accessibility of classes, methods, and variables. There are four access modifiers in Java:

  1. public: Allows access from anywhere, including outside the package.
  2. protected: Allows access from within the same package and from subclasses, even if they are in different packages.
  3. private: Limits access to within the same class only.
  4. Default (no modifier): Allows access from within the same package only.

In this question, the keyword that can protect a class in a package from accessibility by the classes outside the package is the default access modifier (no keyword at all). When a class does not have an access modifier specified, it is considered to have default access. This means that the class can be accessed only by other classes within the same package.

Option A) private: This option is incorrect because the private access modifier restricts access to within the same class, not the same package. Option B) final: This option is incorrect because the final keyword is used to prevent a class from being subclassed, but it does not restrict access from outside the package. Option C) protected: This option is incorrect because the protected access modifier allows access from subclasses and classes within the same package, but it does not restrict access from outside the package. Option D) Don't use any keyword at all (make it default): This option is correct. By not specifying any access modifier, the class will have default access and can only be accessed by other classes within the same package.

Therefore, the correct answer is option D.

Which of the following statements about abstract methods/classes in Java are true? 1. An abstract class cannot be instantiated. 2. Constructors cannot be abstract. 3. A subclass of an abstract class must defined the abstract methods. 4. Static methods may be declared abstract.

  1. Line 1, line 2 and line 3 only

  2. b.Line 1 only

  3. c.Line 1 and line 2 only

  4. d.Line 2 only


Correct Option: C

The use of protected keyword to a member in a class will restrict its visibility as follows:

  1. Visible only inside the package.

  2. b.Visible only in the class and its subclass in the same package.

  3. c.Visible in all classes in the same package and subclasses in other packages.

  4. d.Visible only in the class where it is declared.


Correct Option: C

AI Explanation

To answer this question, you need to understand the visibility modifiers in Java.

The protected keyword is a visibility modifier in Java that restricts the visibility of a member (variable or method) in a class.

Option A) Visible only inside the package - This option is incorrect. The protected keyword provides visibility not only within the package but also to subclasses in other packages.

Option B) Visible only in the class and its subclass in the same package - This option is incorrect. The protected keyword provides visibility not only within the same package but also to subclasses in other packages.

Option C) Visible in all classes in the same package and subclasses in other packages - This option is correct. The protected keyword allows the member to be visible in all classes in the same package and subclasses in other packages.

Option D) Visible only in the class where it is declared - This option is incorrect. The protected keyword provides visibility to subclasses in other packages as well.

The correct answer is Option C. This option is correct because the protected keyword allows the member to be visible in all classes in the same package and subclasses in other packages.

Which of the following are keywords? (A) switch (B) integer (C) default (D) boolean (E) object

  1. (B) & (C)

  2. b. (E)

  3. c. (A) & (C)

  4. d. (D)


Correct Option: C

The keywords reserved but not used in the initial version of Java are: (A) union (B) const (C) inner (D) goto (E) boolean (F) synchronized

  1. All of these.

  2. b. (C) & (E)

  3. c. (A), (C) & (E)

  4. d. (B),(C) & (D)


Correct Option: D

We would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would achieve this?

  1. private

  2. 0

  3. c. private OR protected

  4. d. protected


Correct Option: C

The keywords reserved but not used in the initial version of Java are: (A) union (B) const (C) inner (D) goto (E) boolean (F) synchronized

  1. All of these.

  2. b. (C) & (E)

  3. c. (A), (C) & (E)

  4. d. (B),(C) & (D)


Correct Option: C