Java 2 Flashcards

1
Q

What is the difference between static and final variables?

A

Static variable is a global variable shared by all the instances of objects and it has only single copy. A final variable is a constant variable and it cannot be changed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the implicit modifiers required for interface variables?

A

public static final

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are transient variables?

A

Transient variables are those variables which cannot be serialized.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are access modifiers?

A
public  – can be accessed from any package.								
private – only members of the same class can access.								
protected – can be accessed by classes inside the package and subclasses anywhere.								
default - no access by classes or subclasses outside the package
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a wrapper class?

A

Wrapper class is a wrapper around a primitive data type. It represents primitive data types in their corresponding class instances e.g. a boolean data type can be represented as a Boolean class instance. All of the primitive wrapper classes in Java are immutable i.e. once assigned a value to a wrapper class instance cannot be changed further.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Reflection API?

A
The first component of the Reflection API is the mechanism used to fetch information about a class. This mechanism is built into the class named Class. The special class Class is the universal type for the meta information that describes objects within the Java system. Class loaders in the Java system return objects of type Class. Up until now the three most interesting methods in this class were: 
forName, which would load a class of a given name, using the current class loader
getName, which would return the name of the class as a String object,which was useful for identifying object references by their class name
newInstance, which would invoke the null constructor on the class (if it exists) and return you an object instance of that class of object 

To these three useful methods the Reflection API adds some additional methods to class Class. These are as follows:
getConstructor, getConstructors, getDeclaredConstructor
getMethod, getMethods, getDeclaredMethods
getField, getFields, getDeclaredFields
getSuperclass
getInterfaces
getDeclaredClasses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Is Java pass by value or pass by reference?

A

Java is strictly pass by value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is encapsulation?

A

Encapsulation can be described as a protective barrier that prevents the code and data being randomly accessed by other code defined outside the class. Access to the data and code is tightly controlled by an interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In what ways can you create a thread?

A

By extending the Thread Class or by implementing the Runnable Interface. You must call Thread’s start() method to start it as a new thread of execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference between “==” and equals()?

A

”==” - tests to see if two reference variables refer to the exact same instance of an object.

equals() - tests to see if the two objects being compared to each other are equivalent, but they need not be the exact same instance of the same object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is polymorphism?

A

Subclasses of a class can define their own unique behaviors and yet share some of the same functionality of the parent class. An object can also be referenced by its supertype “parent” class, for example ParentClass obj = new SubClass( );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is inheritance?

A

A class that is derived from another class is called a subclass (also a derived class, extended class, or child class). The class from which the subclass is derived is called a superclass (also a base class or a parent class).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between method overriding and method overloading?

A

Method overriding - In a subclass when one declares an identical method from the superclass, this method overrides the one in the superclass.

Method overloading - Within the same class when one declares more than method with the same name but different signature (parameters).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly