Java Developer OCA Questions Flashcards
99 Questions
100 Views

Java Developer OCA Questions Flashcards

Created by
@RapturousSunflower

Questions and Answers

It can be extended by another interface.

False

Tell me about the keyword implements.

The keyword implements is used when a class inherits method prototypes from an interface.

Which logical operators are known as 'short circuiting logical operators'?

|| and &&

By default (i.e. no modifier) the member is only accessible to classes in the same package and subclasses of the class.

<p>False</p> Signup and view all the answers

You cannot specify visibility of local variables.

<p>True</p> Signup and view all the answers

Local variables always have default accessibility.

<p>False</p> Signup and view all the answers

Local variables can be declared as private.

<p>False</p> Signup and view all the answers

Local variables can only be declared as public.

<p>False</p> Signup and view all the answers

A functional interface has exactly one method and it must be abstract.

<p>False</p> Signup and view all the answers

A functional interface has exactly one method and it may or may not be abstract.

<p>False</p> Signup and view all the answers

A functional interface must have exactly one abstract method and may have other default or static methods.

<p>True</p> Signup and view all the answers

A functional interface must have exactly one static method and may have other default or abstract methods.

<p>False</p> Signup and view all the answers

The 'default' constructor is provided by the compiler only if the class and any of its super classes does not define any constructor.

<p>False</p> Signup and view all the answers

The 'default' constructor takes no arguments.

<p>True</p> Signup and view all the answers

A default constructor is used to return a default value.

<p>False</p> Signup and view all the answers

To define a default constructor, you must use the default keyword.

<p>False</p> Signup and view all the answers

The 'default' constructor is always public.

<p>False</p> Signup and view all the answers

Using a continue in a while loop causes the loop to break the current iteration and start the next iteration of the loop.

<p>True</p> Signup and view all the answers

A character literal can be used as a value for a case label.

<p>True</p> Signup and view all the answers

A 'long' cannot be used as a switch variable.

<p>True</p> Signup and view all the answers

An empty switch block is a valid construct.

<p>True</p> Signup and view all the answers

A switch block must have a default label.

<p>False</p> Signup and view all the answers

If present, the default label must be the last of all the labels.

<p>False</p> Signup and view all the answers

What is java.util.function.Predicate?

<p>It is an interface that has only one abstract method with the signature public boolean test(T t).</p> Signup and view all the answers

A method with no access modifier defined in a class can be overridden by a method marked protected in the subclass.

<p>True</p> Signup and view all the answers

Using a break in a while loop causes the loop to break the current iteration and start the next iteration of the loop.

<p>False</p> Signup and view all the answers

What class of objects can be declared by the throws clause?

<p>All of the above</p> Signup and view all the answers

Tell me something about scope.

<p>Class level means static fields that can be accessed anywhere in the class; instance level means instance fields accessible only from instance methods.</p> Signup and view all the answers

Which class should you use to represent just a date without any timezone information?

<p>java.time.LocalDate</p> Signup and view all the answers

A try statement must always have a ________ associated with it.

<p>catch, finally or both</p> Signup and view all the answers

Does the String class have a reverse method?

<p>False</p> Signup and view all the answers

Tell me something about fields in an interface.

<p>Fields in an interface are implicitly public, static, and final.</p> Signup and view all the answers

What happens when you call System.exit(0) in a try block followed by a finally block?

<p>The JVM exits, so the finally block will not execute.</p> Signup and view all the answers

What are the primitive data types?

<p>boolean, byte, short, char, int, long, float, and double.</p> Signup and view all the answers

What is the correct declaration for an abstract method 'add' that takes no arguments and returns nothing?

<p>abstract public void add() throws Exception;</p> Signup and view all the answers

What does the zeroth element of the string array passed to the standard main method contain?

<p>The first argument of the argument list, if present.</p> Signup and view all the answers

Which exception should a Java programmer throw explicitly?

<p>Exception</p> Signup and view all the answers

Identify the valid members of Boolean class.

<p>valueOf(boolean)</p> Signup and view all the answers

An abstract class can be extended by an abstract or a concrete class.

<p>True</p> Signup and view all the answers

An abstract class cannot implement an interface.

<p>False</p> Signup and view all the answers

A concrete class can be extended by an abstract or a concrete class.

<p>True</p> Signup and view all the answers

An interface can be extended by another interface.

<p>True</p> Signup and view all the answers

An interface can be extended by an abstract class.

<p>False</p> Signup and view all the answers

The modulus operator % can only be used with integer operands.

<p>False</p> Signup and view all the answers

The arithmetic operators *, / and % have the same level of precedence.

<p>True</p> Signup and view all the answers

&& can have integer as well as boolean operands.

<p>False</p> Signup and view all the answers

~ can have integer as well as boolean operands.

<p>False</p> Signup and view all the answers

How many times can the keyword 'package' appear in a Java source file?

<p>Once.</p> Signup and view all the answers

LocalDate, LocalTime, and LocalDateTime extend Date.

<p>False</p> Signup and view all the answers

LocalDate, LocalTime, and LocalDateTime implement TemporalAccessor.

<p>True</p> Signup and view all the answers

Both LocalDate and LocalTime extend LocalDateTime, which extends java.util.Date.

<p>False</p> Signup and view all the answers

LocalDate, LocalTime, and LocalDateTime implement TemporalAccessor and extend java.util.Date.

<p>False</p> Signup and view all the answers

What is the correct order of restrictiveness for access modifiers?

<p>public, protected, package (no modifier), private</p> Signup and view all the answers

Are private members inherited?

<p>False</p> Signup and view all the answers

What can be the type of a catch argument?

<p>Any class that is a Throwable.</p> Signup and view all the answers

If a RuntimeException is not caught, the method will terminate and normal execution of the thread will resume.

<p>False</p> Signup and view all the answers

An overriding method must declare that it throws the same exception classes as the method it overrides.

<p>False</p> Signup and view all the answers

The main method of a program can declare that it throws checked exceptions.

<p>False</p> Signup and view all the answers

A method declaring that it throws a certain exception class may throw instances of any subclass of that exception class.

<p>True</p> Signup and view all the answers

Finally blocks are executed if and only if an exception gets thrown while inside the corresponding try block.

<p>False</p> Signup and view all the answers

Tell me more about how exceptions are handled.

<p>If an exception is uncaught, it propagates up the call stack until handled or terminates the thread.</p> Signup and view all the answers

Is it possible to create arrays of length zero?

<p>False</p> Signup and view all the answers

The 'default' constructor is provided by the compiler only if the class does not define any constructor.

<p>True</p> Signup and view all the answers

The 'default' constructor initializes the instance members of the class.

<p>False</p> Signup and view all the answers

The 'default' constructor calls the no-args constructor of the super class.

<p>True</p> Signup and view all the answers

The 'default' constructor initializes instance as well as class fields of the class.

<p>False</p> Signup and view all the answers

The 'default' constructor is provided by the compiler if the class does not define a 'no-args' constructor.

<p>False</p> Signup and view all the answers

The private keyword can never be applied to a class.

<p>False</p> Signup and view all the answers

The synchronized keyword can never be applied to a class.

<p>True</p> Signup and view all the answers

The synchronized keyword may be applied to a non-primitive variable.

<p>False</p> Signup and view all the answers

The final keyword can never be applied to a class.

<p>False</p> Signup and view all the answers

A final variable can be hidden in a subclass.

<p>True</p> Signup and view all the answers

Tell me about the final keyword.

<p>The final keyword means that the class cannot be subclassed, the method cannot be overridden, and the variable is a constant.</p> Signup and view all the answers

How can you declare a method someMethod() such that an instance of the class is not needed to access it?

<p>all of the above</p> Signup and view all the answers

Is this a valid declaration in a class? abstract int absMethod(int param) throws Exception;

<p>False</p> Signup and view all the answers

Is this a valid declaration in a class? abstract native int absMethod(int param) throws Exception;

<p>False</p> Signup and view all the answers

Is this a valid declaration in a class? float native getVariance() throws Exception;

<p>False</p> Signup and view all the answers

Is this a valid declaration in a class? abstract private int absMethod(int param) throws Exception;

<p>False</p> Signup and view all the answers

Subclasses must define all the abstract methods that the superclass defines.

<p>False</p> Signup and view all the answers

A class implementing an interface must define all the methods of that interface.

<p>False</p> Signup and view all the answers

A class cannot override the superclass's constructor.

<p>True</p> Signup and view all the answers

It is possible for two classes to be the superclass of each other.

<p>False</p> Signup and view all the answers

An interface can implement multiple interfaces.

<p>False</p> Signup and view all the answers

List three classes that can be thrown using a throw statement.

<p>Exception</p> Signup and view all the answers

Private methods cannot be overridden in subclasses.

<p>True</p> Signup and view all the answers

A subclass can override any method in a non-final superclass.

<p>False</p> Signup and view all the answers

An overriding method can declare that it throws a wider spectrum of checked exceptions than the method it is overriding.

<p>False</p> Signup and view all the answers

The parameter list of an overriding method must be a subset of the parameter list of the method that it is overriding.

<p>False</p> Signup and view all the answers

The overriding method may opt not to declare any throws clause even if the original method has a throws clause.

<p>True</p> Signup and view all the answers

The extends keyword is used to specify inheritance.

<p>True</p> Signup and view all the answers

A subclass of a non-abstract class cannot be declared abstract.

<p>False</p> Signup and view all the answers

A subclass of an abstract class can be declared abstract.

<p>True</p> Signup and view all the answers

A subclass of a final class can be abstract.

<p>False</p> Signup and view all the answers

A class, in which all the members are declared private, cannot be declared public.

<p>False</p> Signup and view all the answers

An interface may extend an interface.

<p>True</p> Signup and view all the answers

An interface may extend a class and may implement an interface.

<p>False</p> Signup and view all the answers

A class can implement an interface and extend a class.

<p>True</p> Signup and view all the answers

A class can extend an interface and can implement a class.

<p>False</p> Signup and view all the answers

An interface can only be implemented and cannot be extended.

<p>False</p> Signup and view all the answers

Study Notes

Java Developer OCA Questions Overview

  • java.util.function.Predicate is a functional interface with a single abstract method public boolean test(T t), representing a condition for evaluating values.
  • Methods without access modifiers can be overridden in subclasses by protected methods, as protected access is more permissive.
  • The break statement in loops terminates the loop immediately; it does not initiate the next iteration.
  • The throws clause can declare any class that extends Throwable, including Exception, Error, and RuntimeException.
  • Scope defines the visibility of fields: class level fields (static) can be accessed anywhere in the class, while instance level fields can only be accessed by instance methods.
  • Use java.time.LocalDate to represent dates without time zones; it is recommended over the old java.util.Date class.
  • Every try statement must have either a catch, finally, or both associated with it.
  • The String class does not have a reverse method; however, StringBuffer and StringBuilder do.
  • Fields in an interface are implicitly public, static, and final, although declaring these keywords is not a good practice.
  • Calling System.exit(0) in a try block bypasses any finally block execution, as the JVM exits immediately.
  • Java primitive data types include boolean, byte, short, char, int, long, float, and double.
  • An abstract method declaration can be abstract public void add() throws Exception;, allowing it to be overridden by subclasses.

Exception Handling

  • The zeroth element in the main method's argument array contains the first argument passed; an empty array signifies no arguments were provided.
  • Exception is appropriate for use in a desktop application for known exceptional situations, unlike Error and RuntimeException, which are typically not thrown explicitly.
  • Valid members of the Boolean class include parseBoolean(String), valueOf(boolean), and the static member FALSE.
  • An abstract class can be extended by another abstract or concrete class, while it can also implement an interface.
  • Interfaces can extend other interfaces but are not allowed to be directly extended by classes; classes implement interfaces instead.

Operators and Access Modifiers

  • The modulus operator % can operate on both integer and floating-point numbers.
  • The & operator can accept both integral and boolean operands without short-circuiting, unlike &&.
  • Arithmetic operators *, /, and % share the same level of precedence in Java.
  • The order of access modifiers from least to most restrictive is public, protected, package-private (default), and private.
  • Private members of a class are not inherited by subclasses; only protected and public members are.
  • Catch argument types in exception handling can be any class extending Throwable.

Class and Interface Relationships

  • A class must define all abstract methods it inherits unless it is also declared abstract.
  • A class implementing an interface must fulfill all its method contracts unless declared abstract.
  • Constructors are not inherited, so a class cannot override super class constructors.
  • Local variables have no visibility modifiers, being accessible only within the block they are declared, and cannot be declared as public or private.
  • A functional interface is defined as having exactly one abstract method (may or may not be abstract in practice).

Additional Java Concepts

  • synchronized can be applied only to methods or blocks but not directly to classes.
  • The final keyword prevents a class from being subclassed, a method from being overridden, or a variable from being reassigned.
  • It is permissible to create zero-length arrays; for example, in the absence of command-line arguments passed to a Java application.
  • The implements keyword is used when a class declares that it conforms to the method structure of an interface.
  • Short-circuit logical operators in Java are || and &&, which may stop evaluation if the result is already determinable.### Functional Interfaces
  • A functional interface must have exactly one abstract method, but may have other default or static methods.
  • A functional interface does not require exactly one static method; it can have zero or more static methods.

Default Constructor

  • The default constructor is provided by the compiler if the class does not define any constructor, regardless of the parent class's constructors.
  • A default constructor is characterized by taking no arguments.
  • Constructors do not return values; their purpose is to initialize an object's state.
  • Defining a default constructor does not require using the keyword "default."
  • The access modifier of a default constructor matches the access modifier of the class it belongs to.

Control Flow in Loops

  • The continue statement in a while loop causes the current iteration to stop and begins the next iteration.
  • The continue statement skips the remaining lines in the loop for the current iteration and checks the loop's condition before continuing.

Switch Statement Characteristics

  • A character literal can be used as a case label in a switch statement.
  • Types such as boolean, long, float, and double are not valid as switch variables.
  • An empty switch block is syntactically valid.
  • A switch block does not require a default label; it can function without one.
  • The default label, if included, can appear in any order within the switch block.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Description

Test your knowledge with these flashcards designed for the OCA Java Developer certification. Each card presents a question related to Java programming concepts and best practices. Ideal for quick revision and effective learning!

More Quizzes Like This

Use Quizgecko on...
Browser
Browser