True/false game Flashcards
2Next is a legal identifier.
False
Non static methods can access static as well as non static methods of a class.
True
do is a keyword so do() is not a valid method name.
True
A class having no abstract method can’t still be abstract. But not vice-versa.
False
A class having no abstract method can still be abstract. But not vice-versa.
True
final static public void main (String[ ] arguments ) { } is valid.
True
InputException and MemoryException are valid exceptions in Java
False
FileNotFoundException and SecurityException are valid exceptions in Java
True
If a.equals(b) returns true, b instanceof ClassOfA must always be true.
False
The array consumes less memory than the ArrayList
True
Accessing an element in an array is faster than in ArrayList.
True
arrays implements Collection Interface
False
Accessing implements Collection Interface
True
A “default” constructor calls the no-args constructor of the super class.
True
float f = -123; is valid
True
It is not possible to create arrays of length zero
False
A static method can’t access non-static instance variables of a class.
True
StringBuilder sb1 = new StringBuilder() will create a StringBuilder object with no characters, but with an initial capacity to store 16 chars.
True
StringBuilder sb1 = new StringBuilder(5*10) will create a StringBuilder object with a value 50.
False
The insert method can be used to insert a character, number, or String at the start or end or a specified position of a StringBuilder.
True
A class can’t define multiple main methods.
True
More than one class in an application can define the main method.
True
The main method may accept a String, a String array, or varargs (String… arg) as a method argument.
False
The main method shouldn’t define an object of the class in which the main method itself is defined.
False
The following is valid: static import java.lang.System.*;
False
A variable can be synchronized
False
A local variable can be volatile
False
A constructor can be final
False
A local variable can be transient
False
Only member variables can be volatile
True
Only member variables can be transient
True
A constructor can be static
False
A constructor can be abstract
False
ArrayList extends java.util.AbstractList
True
System.gc() suggests JVM to do garbage collection
True
Static methods are not overridden, but shadowed
True
strictfp is a keyword in java
True
do is a keyword in java
True
unsigned is a keyword in java
False
A short can be assigned to a char without casting
False
We cannot use this/super in static methods
True
The variables of an interface are public, final and static
True
The methods of an interface are public and abstract
True
The methods of an interface can be final
False
The methods of an interface can be static
False
A derived class is abstract if it doesn’t implement all the abstract methods of it’s based class
True
length() is a method of the Array class
False
length() is a method of the String class
True
StringBuilder has a method concat()
False
String has a method append()
False
StringBuilder has a method trim()
False
The method append() of StringBuilder can take a String, char[ ], Boolean)
True
The method substring() of String takes only int or char
True
The class string has a method .intern()
True
ArrayList can take duplicate values
True
Method clone() of ArrayList creates a copy in a different object and the elements inside it point at the same place
True
An else statement without an if block doesn’t compile
True
An if statement without a block of code doesn’t compile
False
Switch can take long, float or double
False
Switch can take booleans
False
Enhanced for loop cannot be used within a do-while loop
True
Enhanced for loop has a counter variable for the position
False
A class variable is not static
False
The main method can throw exceptions
True
Top-level classes cannot be private, protected or static
True
An abstract class doesn’t need to have abstract methods
True
Abstract methods can’t be in a normal class
True
Abstract methods don’t have body
True
An interface can be final
False
A final method can be overridden
False
Static methods can’t be abstract
True
Static methods can use non-static variables
False
A byte fits in an int
True
= has precendence over ==
False
Methods can return an interface
True
ArrayIndexOutOfBoundsException is a subclass of IndexOutOfBoundsException
True
To access a superclass variable that is shadowed you can use casting
True
To access a superclass method that is shadowed you can use casting
False
String has the method reverse()
False
String has the method hasCode()
True
An interface can extend another interface
True
A class can be synchronized
False
String class is final
True
StringBuilder class is final
True
Integer class is final
True
java.lang.system class is final
True
a constructor must throw the exception of its base class constructor or a super exception
True
an overriding method can throw a super class exception of the base method’s exception
False
an overriding method must return the same type if it’s a primitive
True
an overriding method might return a different type
True
ensureCapacity() is a method of StringBuilder
True
setLength() is a method of StringBuilder
True
if a base-class method is set as default, the overriding method can be set protected
True
Only methods can be native
True
Static methods may or may not be abstract
False
& can have integral and Boolean operands but && can only have Boolean operands
True
/, * and % have the same level of precedence
True
% can only be used with integer operands
False
You can define a member variable as private static final transient
True
Integer values can be used in the condition of an if statement
False
An overriding method may opt not to declare any throws clause even if the original method has a throws clause
True
A class cannot override a super-class’ constructor
True
Constructors cannot be abstract
True
Constructors cannot have empty bodies
True
Encapsulation helps make sure that clients have no accidental dependence on the choice of representation
True
Encapsulation helps avoiding name clashes as internal variables are not visible outside
True
Encapsulation makes sure that messages are sent to the right object at run time
False
Dynamic binding is an outcome of polymorphism
True
Encapsulation helps you inherit the properties of another class
False
assert is a keyword in java
True
const is a keyword in java
True
Members of an interface may be static
True
The methods of an interface are static
False
instanceof is a java operator
True
You can sort the elements of an ArrayList using Collection.sort()
True
You must specify the class of the objects you want to store in an ArrayList when you declare a variable of type ArrayList
False
StackOverflowError and OutOfMemoryError ar subclasses of VirtualMachineError
True
new StringBuilder() creates an object of StringBuilder with capacity for 16 chars
True
MemoryOutOfBounds exception is a subclass of RuntimeException
False
An abstract class cannot implement an interface
False
A concrete class can be extended by an abstract or a concrete class
True
double/float/long/boolean are invalid in a switch
True
Is it possible to create arrays of length zero
True