stud
bud
Sign up
Log in
Home
Library
Explore
SAT
More
Java Test Flashcards | StudBud
Explore
/
Java Test
Java Test
65 terms
·
StudBud Administration
·
26 plays
Imported from external platform
Flashcards
65 cards
F
Practice quiz
P
Host live
L
Questions
65
Answers
1
Which of these is the correct way to declare a variable age and make it equal to 18?
int age = 18;
age = 18;
int age = 18
integer age = 18;
2
A static method _______ .
belongs to the class rather than object of a class
can be invoked only with the instance of a class
may create unnecessary errors
All the above
3
Which data type is used to create a variable that should store text?
boolean
int
double
String
4
The name of the constructor must be?
Creator
Constructor
Can be called anything
The same as the class
5
Default constructors are constructors ________ parameters.
with 1
without any
with more than 2
with
6
A subclass is also known as?
a superclass or parent class
a child class or derived class
a base class or derived class
a child class or base class
7
The _______ relationship is used to describe inheritance relationships.
could-be-a
is-a
has-a
was-a
8
Can an abstract method be defined in a non-abstract class?
Yes - as long as the children are abstract
No - if a class defines an abstract method must be abstract.
Yes - there is no restriction on where abstract methods can be
No - only classes are abstract, not methods
9
When you refer to the superclass in the constructor of subclass....
it must always come at the end of the constructor
it must be the first line in the constructor
the order does not matter
none of these
10
Java is short for "JavaScript".
False
True
11
Encapsulation is implemented by using ______?
static
class
public
private
12
What happens if you create a class but don't create constructor?
There would be a compile-time error.
Java creates a default (no parameter) constructor for you
There would be a run-time error.
You can have classes without constructors
13
Can an abstract class define both abstract methods and non-abstract methods?
Yes—the child classes inherit both.
Yes—but the child classes don't inherit the abstract methods
No—it must have all abstract methods.
No—it must have all one or the other.
14
Which of the following is TRUE about abstract methods?
Abstract methods must be overridden by the super-class(es)
An abstract method is a method that is declared only (without a body)
An abstract method is any method in an abstract class
An abstract method cannot be inherited
15
Which of the following can you override?
A static method
A final method
An instance method
A private method
16
What is the term in programming that means many forms?
Encapsulation
Polymorphism
Inheritance
Extension
17
Which of these keywords is used to refer to member of base class from a sub class?
this
super
none of these
upper
18
Which is the correct way to initialize an array of Strings?
String[] animals = {dog, cat, horse};
String animals = {"dog", "cat", "horse"};
String[] animals = {"dog", "cat", "horse"};
animals = {dog, cat, horse};
19
What is a constructor?
A type of object constructed by the System at start up
There's no such term in Java
A block of code creating instances of a class
Special class name
20
Which of these keyword must be used to inherit a class?
extends
super
subclass
create
21
Can an abstract method be defined in a non abstract class?
No—only classes are abstract, not methods
No—if a class defines an abstract method must be abstract.
Yes—as long as the children are abstract
Yes—there is no restriction on where abstract methods can be
22
What is FALSE about static methods?
Can use static data
Can be called on classes
Can use instance data
Can be called on objects
23
An abstract class can be instantiated if it contains NO abstract methods?
True
False
24
Why do you use while loops in Java?
To break out of some block of code
To repeat some code while a condition is true
To repeat something for a fixed number of times while a condition is TRUE
There isn't while loop in Java
25
What is the correct way to compare Strings?
name && Lucky;
name.equals("Lucky");
name = "Lucky";
name == "Lucky";
26
Can you have multiple constructors?
Yes, if they have different names
Only two
No, only one
Yes, if they have different signatures
27
What is the correct way to create an object called myObj of MyClass?
MyClass myObj = new MyClass();
new myObj = MyClass();
class myObj = new MyClass();
class MyClass = new myObj();
28
Java will ALWAYS provide default constructor for you?
False
True
29
Polymorphism is accomplished by using which of the following?
all of these
abstract classes
parent classes
interfaces
30
Are constructors inherited?
False
True
31
How do you create a variable with the floating number 2.8?
double x = 2.8;
number x = 2.8;
int x = 2.8;
byte x = 2.8;
32
Scanner is a?
method
statement
loop
class
33
Inheritance allows you ______ .
Duplicate code
Reuse code
Reinvent code
Put more effort into programming
34
How do you insert COMMENTS in Java code?
#This is a comment
%This is a comment
*This is a comment*
//This is a comment
35
Which keyword is required to used an interface?
has-a
extends
abstract
implements
36
What is a correct syntax to output "Hello World" in Java?
print("Hello World");
System.out.println("Hello World");
Console.WriteLine("Hello World");
echo("Hello World");
37
What is an advantage of polymorhpism?
Making new objects from old objects of like type saves time
The same logic can be used with objects of different types
Variables can be re-used in order to save memory
Polymorphism is dangerous and should be avoided
38
Which variable type would you use if you want to declare the value to be one letter?
int
boolean
String
char
39
What does Java insert in the space indicated by the comment?
super(); this();
super();
this(); super();
this();
40
Which is the correct way to initialize an array of integers?
int[] numbers = [1,2,3,4,5,6];
int[] numbers = {1,2,3,4,5,6};
int numbers = {1,2,3,4,5,6};
int{} numbers = {1,2,3,4,5,6};
41
How do you create a variable with the numeric value 5?
x = 5;
number x = 5
int x = 5;
double x = 5;
42
The final keyword with a variable makes it a:
Class
Constant
String
integer
43
Which is a process of hiding the implementation details and showing only functionality to the user?
Polymorphism
Abstraction
Encapsulation
Inheritance
44
Which is the correct output of the following code?
Take sunglassess
Take an umbrella
rainy
sunny
45
Encapsulation is also called as?
Data showing
Data Hiding
Closing
None of the above
46
What means FINAL method?
The method cannot be overridden
The method can be overridden
There's no such keyword in Java
The method cannot be invoked
47
What is a final class?
A class with only private data and private methods
A class that cannot be instantiated
A class that cannot be inherited
Final classes doesn't exist in Java
48
Overriding is?
Redefining methods that were inherited from a parent class
Writing methods in an abstract class
Implementing methods of an interface
Having more than 1 method with the same name but different signatures
49
What is it called when you set the starting value of the variable?
declaring
stating
initializing
setting
50
Array indexes start from 1.
False
True
51
An animal class is abstract. Cat and Dog are concrete subclasses of Animal. Which is legal?
Dog d = new Cat();
Animal a = new Animal();
Animal a = new Cat();
Cat c = new Animal();
52
What kind of inhertiance Java does not support?
Multi level inheritance
Single inheritance
Multiple inheritance
Hierarchical inheritance
53
What is an object in OOP?
A declaration statement
An instance of a class
The process of inheritance
A class definition
54
If a class X extends B then what relation is created between X & B?
B has a X
X is a B
B is a X
X has a B
55
What is the output of the following code?
1
6.0
2
2.0
56
What will this loop do:
Print all numbers from 0 to 50
Print all numbers from 1 to 49
Print all numbers from 1 to 50
Print all numbers from 0 to 49
57
What are the 4 OOP concepts in Java?
Encapsulation, Class, Abstraction, Final
Encapsulation, Inheritance, static, final
Encapsulation, Inheritance, Abstraction, Polymorphism
Encapsulation, Inheritance, Private, Public
58
Which operator is used to multiply numbers?
x
^
+
*
59
To declare an array in Java what kind of brackets do you use?
{}
()
[]
(]
60
What is Java?
First program you interact with when turning on a computer
A location of data
Coffee
Object oriented programming language
61
Each statement in Java should end with a ______
quotation
round bracket
curly bracket
semicolon
62
Can an abstract class have an abstract children?
True
False
63
Which of the following describes an abstract class?
A super class with more than one sub class
A class that can't be instantiated
A class without any subclasses
Another name for a super (base) class
64
You can use static data in instance methods?
False
True
65
Which operator can be used to compare two values for equality?
==
!=
<>
=