Podcast
Questions and Answers
It can be extended by another interface.
It can be extended by another interface.
False
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.
Signup and view all the answers
You cannot specify visibility of local variables.
You cannot specify visibility of local variables.
Signup and view all the answers
Local variables always have default accessibility.
Local variables always have default accessibility.
Signup and view all the answers
Local variables can be declared as private.
Local variables can be declared as private.
Signup and view all the answers
Local variables can only be declared as public.
Local variables can only be declared as public.
Signup and view all the answers
A functional interface has exactly one method and it must be abstract.
A functional interface has exactly one method and it must be abstract.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
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.
The 'default' constructor is provided by the compiler only if the class and any of its super classes does not define any constructor.
Signup and view all the answers
The 'default' constructor takes no arguments.
The 'default' constructor takes no arguments.
Signup and view all the answers
A default constructor is used to return a default value.
A default constructor is used to return a default value.
Signup and view all the answers
To define a default constructor, you must use the default keyword.
To define a default constructor, you must use the default keyword.
Signup and view all the answers
The 'default' constructor is always public.
The 'default' constructor is always public.
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.
Using a continue in a while loop causes the loop to break the current iteration and start the next iteration of the loop.
Signup and view all the answers
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.
Signup and view all the answers
A 'long' cannot be used as a switch variable.
A 'long' cannot be used as a switch variable.
Signup and view all the answers
An empty switch block is a valid construct.
An empty switch block is a valid construct.
Signup and view all the answers
A switch block must have a default label.
A switch block must have a default label.
Signup and view all the answers
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.
Signup and view all the answers
What is java.util.function.Predicate?
What is java.util.function.Predicate?
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.
A method with no access modifier defined in a class can be overridden by a method marked protected in the subclass.
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.
Using a break in a while loop causes the loop to break the current iteration and start the next iteration of the loop.
Signup and view all the answers
What class of objects can be declared by the throws clause?
What class of objects can be declared by the throws clause?
Signup and view all the answers
Tell me something about scope.
Tell me something about scope.
Signup and view all the answers
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?
Signup and view all the answers
A try statement must always have a ________ associated with it.
A try statement must always have a ________ associated with it.
Signup and view all the answers
Does the String class have a reverse method?
Does the String class have a reverse method?
Signup and view all the answers
Tell me something about fields in an interface.
Tell me something about fields in an interface.
Signup and view all the answers
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?
Signup and view all the answers
What are the primitive data types?
What are the primitive data types?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
Which exception should a Java programmer throw explicitly?
Which exception should a Java programmer throw explicitly?
Signup and view all the answers
Identify the valid members of Boolean class.
Identify the valid members of Boolean class.
Signup and view all the answers
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.
Signup and view all the answers
An abstract class cannot implement an interface.
An abstract class cannot implement an interface.
Signup and view all the answers
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.
Signup and view all the answers
An interface can be extended by another interface.
An interface can be extended by another interface.
Signup and view all the answers
An interface can be extended by an abstract class.
An interface can be extended by an abstract class.
Signup and view all the answers
The modulus operator % can only be used with integer operands.
The modulus operator % can only be used with integer operands.
Signup and view all the answers
The arithmetic operators *, / and % have the same level of precedence.
The arithmetic operators *, / and % have the same level of precedence.
Signup and view all the answers
&& can have integer as well as boolean operands.
&& can have integer as well as boolean operands.
Signup and view all the answers
~ can have integer as well as boolean operands.
~ can have integer as well as boolean operands.
Signup and view all the answers
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?
Signup and view all the answers
LocalDate, LocalTime, and LocalDateTime extend Date.
LocalDate, LocalTime, and LocalDateTime extend Date.
Signup and view all the answers
LocalDate, LocalTime, and LocalDateTime implement TemporalAccessor.
LocalDate, LocalTime, and LocalDateTime implement TemporalAccessor.
Signup and view all the answers
Both LocalDate and LocalTime extend LocalDateTime, which extends java.util.Date.
Both LocalDate and LocalTime extend LocalDateTime, which extends java.util.Date.
Signup and view all the answers
LocalDate, LocalTime, and LocalDateTime implement TemporalAccessor and extend java.util.Date.
LocalDate, LocalTime, and LocalDateTime implement TemporalAccessor and extend java.util.Date.
Signup and view all the answers
What is the correct order of restrictiveness for access modifiers?
What is the correct order of restrictiveness for access modifiers?
Signup and view all the answers
Are private members inherited?
Are private members inherited?
Signup and view all the answers
What can be the type of a catch argument?
What can be the type of a catch argument?
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
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.
A method declaring that it throws a certain exception class may throw instances of any subclass of that exception class.
Signup and view all the answers
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.
Signup and view all the answers
Tell me more about how exceptions are handled.
Tell me more about how exceptions are handled.
Signup and view all the answers
Is it possible to create arrays of length zero?
Is it possible to create arrays of length zero?
Signup and view all the answers
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.
Signup and view all the answers
The 'default' constructor initializes the instance members of the class.
The 'default' constructor initializes the instance members of the class.
Signup and view all the answers
The 'default' constructor calls the no-args constructor of the super class.
The 'default' constructor calls the no-args constructor of the super class.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
The private keyword can never be applied to a class.
The private keyword can never be applied to a class.
Signup and view all the answers
The synchronized keyword can never be applied to a class.
The synchronized keyword can never be applied to a class.
Signup and view all the answers
The synchronized keyword may be applied to a non-primitive variable.
The synchronized keyword may be applied to a non-primitive variable.
Signup and view all the answers
The final keyword can never be applied to a class.
The final keyword can never be applied to a class.
Signup and view all the answers
A final variable can be hidden in a subclass.
A final variable can be hidden in a subclass.
Signup and view all the answers
Tell me about the final keyword.
Tell me about the final keyword.
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?
How can you declare a method someMethod() such that an instance of the class is not needed to access it?
Signup and view all the answers
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;
Signup and view all the answers
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;
Signup and view all the answers
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;
Signup and view all the answers
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;
Signup and view all the answers
Subclasses must define all the abstract methods that the superclass defines.
Subclasses must define all the abstract methods that the superclass defines.
Signup and view all the answers
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.
Signup and view all the answers
A class cannot override the superclass's constructor.
A class cannot override the superclass's constructor.
Signup and view all the answers
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.
Signup and view all the answers
An interface can implement multiple interfaces.
An interface can implement multiple interfaces.
Signup and view all the answers
List three classes that can be thrown using a throw statement.
List three classes that can be thrown using a throw statement.
Signup and view all the answers
Private methods cannot be overridden in subclasses.
Private methods cannot be overridden in subclasses.
Signup and view all the answers
A subclass can override any method in a non-final superclass.
A subclass can override any method in a non-final superclass.
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.
An overriding method can declare that it throws a wider spectrum of checked exceptions than the method it is overriding.
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.
The parameter list of an overriding method must be a subset of the parameter list of the method that it is overriding.
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.
The overriding method may opt not to declare any throws clause even if the original method has a throws clause.
Signup and view all the answers
The extends keyword is used to specify inheritance.
The extends keyword is used to specify inheritance.
Signup and view all the answers
A subclass of a non-abstract class cannot be declared abstract.
A subclass of a non-abstract class cannot be declared abstract.
Signup and view all the answers
A subclass of an abstract class can be declared abstract.
A subclass of an abstract class can be declared abstract.
Signup and view all the answers
A subclass of a final class can be abstract.
A subclass of a final class can be abstract.
Signup and view all the answers
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.
Signup and view all the answers
An interface may extend an interface.
An interface may extend an interface.
Signup and view all the answers
An interface may extend a class and may implement an interface.
An interface may extend a class and may implement an interface.
Signup and view all the answers
A class can implement an interface and extend a class.
A class can implement an interface and extend a class.
Signup and view all the answers
A class can extend an interface and can implement a class.
A class can extend an interface and can implement a class.
Signup and view all the answers
An interface can only be implemented and cannot be extended.
An interface can only be implemented and cannot be extended.
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 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.
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!