Podcast
Questions and Answers
It can be extended by another interface.
It can be extended by another interface.
False (B)
Tell me about the keyword implements.
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'?
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.
By default (i.e. no modifier) the member is only accessible to classes in the same package and subclasses of the class.
You cannot specify visibility of local variables.
You cannot specify visibility of local variables.
Local variables always have default accessibility.
Local variables always have default accessibility.
Local variables can be declared as private.
Local variables can be declared as private.
Local variables can only be declared as public.
Local variables can only be declared as public.
A functional interface has exactly one method and it must be abstract.
A functional interface has exactly one method and it must be abstract.
A functional interface has exactly one method and it may or may not be abstract.
A functional interface has exactly one method and it may or may not be abstract.
A functional interface must have exactly one abstract method and may have other default or static methods.
A functional interface must have exactly one abstract method and may have other default or static methods.
A functional interface must have exactly one static method and may have other default or abstract methods.
A functional interface must have exactly one static method and may have other default or abstract methods.
The 'default' constructor is provided by the compiler only if the class and any of its super classes does not define any constructor.
The 'default' constructor is provided by the compiler only if the class and any of its super classes does not define any constructor.
The 'default' constructor takes no arguments.
The 'default' constructor takes no arguments.
A default constructor is used to return a default value.
A default constructor is used to return a default value.
To define a default constructor, you must use the default keyword.
To define a default constructor, you must use the default keyword.
The 'default' constructor is always public.
The 'default' constructor is always public.
Using a continue in a while loop causes the loop to break the current iteration and start the next iteration of the loop.
Using a continue in a while loop causes the loop to break the current iteration and start the next iteration of the loop.
A character literal can be used as a value for a case label.
A character literal can be used as a value for a case label.
A 'long' cannot be used as a switch variable.
A 'long' cannot be used as a switch variable.
An empty switch block is a valid construct.
An empty switch block is a valid construct.
A switch block must have a default label.
A switch block must have a default label.
If present, the default label must be the last of all the labels.
If present, the default label must be the last of all the labels.
What is java.util.function.Predicate?
What is java.util.function.Predicate?
A method with no access modifier defined in a class can be overridden by a method marked protected in the subclass.
A method with no access modifier defined in a class can be overridden by a method marked protected in the subclass.
Using a break in a while loop causes the loop to break the current iteration and start the next iteration of the loop.
Using a break in a while loop causes the loop to break the current iteration and start the next iteration of the loop.
What class of objects can be declared by the throws clause?
What class of objects can be declared by the throws clause?
Tell me something about scope.
Tell me something about scope.
Which class should you use to represent just a date without any timezone information?
Which class should you use to represent just a date without any timezone information?
A try statement must always have a ________ associated with it.
A try statement must always have a ________ associated with it.
Does the String class have a reverse method?
Does the String class have a reverse method?
Tell me something about fields in an interface.
Tell me something about fields in an interface.
What happens when you call System.exit(0) in a try block followed by a finally block?
What happens when you call System.exit(0) in a try block followed by a finally block?
What are the primitive data types?
What are the primitive data types?
What is the correct declaration for an abstract method 'add' that takes no arguments and returns nothing?
What is the correct declaration for an abstract method 'add' that takes no arguments and returns nothing?
What does the zeroth element of the string array passed to the standard main method contain?
What does the zeroth element of the string array passed to the standard main method contain?
Which exception should a Java programmer throw explicitly?
Which exception should a Java programmer throw explicitly?
Identify the valid members of Boolean class.
Identify the valid members of Boolean class.
An abstract class can be extended by an abstract or a concrete class.
An abstract class can be extended by an abstract or a concrete class.
An abstract class cannot implement an interface.
An abstract class cannot implement an interface.
A concrete class can be extended by an abstract or a concrete class.
A concrete class can be extended by an abstract or a concrete class.
An interface can be extended by another interface.
An interface can be extended by another interface.
An interface can be extended by an abstract class.
An interface can be extended by an abstract class.
The modulus operator % can only be used with integer operands.
The modulus operator % can only be used with integer operands.
The arithmetic operators *, / and % have the same level of precedence.
The arithmetic operators *, / and % have the same level of precedence.
&& can have integer as well as boolean operands.
&& can have integer as well as boolean operands.
~ can have integer as well as boolean operands.
~ can have integer as well as boolean operands.
How many times can the keyword 'package' appear in a Java source file?
How many times can the keyword 'package' appear in a Java source file?
LocalDate, LocalTime, and LocalDateTime extend Date.
LocalDate, LocalTime, and LocalDateTime extend Date.
LocalDate, LocalTime, and LocalDateTime implement TemporalAccessor.
LocalDate, LocalTime, and LocalDateTime implement TemporalAccessor.
Both LocalDate and LocalTime extend LocalDateTime, which extends java.util.Date.
Both LocalDate and LocalTime extend LocalDateTime, which extends java.util.Date.
LocalDate, LocalTime, and LocalDateTime implement TemporalAccessor and extend java.util.Date.
LocalDate, LocalTime, and LocalDateTime implement TemporalAccessor and extend java.util.Date.
What is the correct order of restrictiveness for access modifiers?
What is the correct order of restrictiveness for access modifiers?
Are private members inherited?
Are private members inherited?
What can be the type of a catch argument?
What can be the type of a catch argument?
If a RuntimeException is not caught, the method will terminate and normal execution of the thread will resume.
If a RuntimeException is not caught, the method will terminate and normal execution of the thread will resume.
An overriding method must declare that it throws the same exception classes as the method it overrides.
An overriding method must declare that it throws the same exception classes as the method it overrides.
The main method of a program can declare that it throws checked exceptions.
The main method of a program can declare that it throws checked exceptions.
A method declaring that it throws a certain exception class may throw instances of any subclass of that exception class.
A method declaring that it throws a certain exception class may throw instances of any subclass of that exception class.
Finally blocks are executed if and only if an exception gets thrown while inside the corresponding try block.
Finally blocks are executed if and only if an exception gets thrown while inside the corresponding try block.
Tell me more about how exceptions are handled.
Tell me more about how exceptions are handled.
Is it possible to create arrays of length zero?
Is it possible to create arrays of length zero?
The 'default' constructor is provided by the compiler only if the class does not define any constructor.
The 'default' constructor is provided by the compiler only if the class does not define any constructor.
The 'default' constructor initializes the instance members of the class.
The 'default' constructor initializes the instance members of the class.
The 'default' constructor calls the no-args constructor of the super class.
The 'default' constructor calls the no-args constructor of the super class.
The 'default' constructor initializes instance as well as class fields of the class.
The 'default' constructor initializes instance as well as class fields of the class.
The 'default' constructor is provided by the compiler if the class does not define a 'no-args' constructor.
The 'default' constructor is provided by the compiler if the class does not define a 'no-args' constructor.
The private keyword can never be applied to a class.
The private keyword can never be applied to a class.
The synchronized keyword can never be applied to a class.
The synchronized keyword can never be applied to a class.
The synchronized keyword may be applied to a non-primitive variable.
The synchronized keyword may be applied to a non-primitive variable.
The final keyword can never be applied to a class.
The final keyword can never be applied to a class.
A final variable can be hidden in a subclass.
A final variable can be hidden in a subclass.
Tell me about the final keyword.
Tell me about the final keyword.
How can you declare a method someMethod() such that an instance of the class is not needed to access it?
How can you declare a method someMethod() such that an instance of the class is not needed to access it?
Is this a valid declaration in a class? abstract int absMethod(int param) throws Exception;
Is this a valid declaration in a class? abstract int absMethod(int param) throws Exception;
Is this a valid declaration in a class? abstract native int absMethod(int param) throws Exception;
Is this a valid declaration in a class? abstract native int absMethod(int param) throws Exception;
Is this a valid declaration in a class? float native getVariance() throws Exception;
Is this a valid declaration in a class? float native getVariance() throws Exception;
Is this a valid declaration in a class? abstract private int absMethod(int param) throws Exception;
Is this a valid declaration in a class? abstract private int absMethod(int param) throws Exception;
Subclasses must define all the abstract methods that the superclass defines.
Subclasses must define all the abstract methods that the superclass defines.
A class implementing an interface must define all the methods of that interface.
A class implementing an interface must define all the methods of that interface.
A class cannot override the superclass's constructor.
A class cannot override the superclass's constructor.
It is possible for two classes to be the superclass of each other.
It is possible for two classes to be the superclass of each other.
An interface can implement multiple interfaces.
An interface can implement multiple interfaces.
List three classes that can be thrown using a throw statement.
List three classes that can be thrown using a throw statement.
Private methods cannot be overridden in subclasses.
Private methods cannot be overridden in subclasses.
A subclass can override any method in a non-final superclass.
A subclass can override any method in a non-final superclass.
An overriding method can declare that it throws a wider spectrum of checked exceptions than the method it is overriding.
An overriding method can declare that it throws a wider spectrum of checked exceptions than the method it is overriding.
The parameter list of an overriding method must be a subset of the parameter list of the method that it is overriding.
The parameter list of an overriding method must be a subset of the parameter list of the method that it is overriding.
The overriding method may opt not to declare any throws clause even if the original method has a throws clause.
The overriding method may opt not to declare any throws clause even if the original method has a throws clause.
The extends keyword is used to specify inheritance.
The extends keyword is used to specify inheritance.
A subclass of a non-abstract class cannot be declared abstract.
A subclass of a non-abstract class cannot be declared abstract.
A subclass of an abstract class can be declared abstract.
A subclass of an abstract class can be declared abstract.
A subclass of a final class can be abstract.
A subclass of a final class can be abstract.
A class, in which all the members are declared private, cannot be declared public.
A class, in which all the members are declared private, cannot be declared public.
An interface may extend an interface.
An interface may extend an interface.
An interface may extend a class and may implement an interface.
An interface may extend a class and may implement an interface.
A class can implement an interface and extend a class.
A class can implement an interface and extend a class.
A class can extend an interface and can implement a class.
A class can extend an interface and can implement a class.
An interface can only be implemented and cannot be extended.
An interface can only be implemented and cannot be extended.
Flashcards are hidden until you start studying
Study Notes
Java Developer OCA Questions Overview
java.util.function.Predicate
is a functional interface with a single abstract methodpublic 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 extendsThrowable
, includingException
,Error
, andRuntimeException
. - Scope defines the visibility of fields:
class level
fields (static) can be accessed anywhere in the class, whileinstance level
fields can only be accessed by instance methods. - Use
java.time.LocalDate
to represent dates without time zones; it is recommended over the oldjava.util.Date
class. - Every
try
statement must have either acatch
,finally
, or both associated with it. - The
String
class does not have areverse
method; however,StringBuffer
andStringBuilder
do. - Fields in an interface are implicitly
public
,static
, andfinal
, although declaring these keywords is not a good practice. - Calling
System.exit(0)
in atry
block bypasses anyfinally
block execution, as the JVM exits immediately. - Java primitive data types include
boolean
,byte
,short
,char
,int
,long
,float
, anddouble
. - 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, unlikeError
andRuntimeException
, which are typically not thrown explicitly.- Valid members of the
Boolean
class includeparseBoolean(String)
,valueOf(boolean)
, and the static memberFALSE
. - 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), andprivate
. - Private members of a class are not inherited by subclasses; only
protected
andpublic
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.