1-10 Flashcards

1
Q

What is the difference between an Inner Class and a Sub-Class?

A

An Inner class is a class which is nested within another class. An Inner class has access rights for the class which is nesting it and it can access all variables and methods defined in the outer class.

A sub-class is a class which inherits from another class called super class. Sub-class can access all public and protected methods and fields of its super class.

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

What are the various access specifiers for Java classes?

A
  1. Public : Class,Method,Field is accessible from anywhere.
  2. Protected:Method,Field can be accessed from the same class to which they belong or from the sub-classes,and from the class of same package,but not from outside.
  3. Default: Method,Field,class can be accessed only from the same package and not from outside of it’s native package.
  4. Private: Method,Field can be accessed from the same class to which they belong.§
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What’s the purpose of Static methods and static variables?

A

When there is a requirement to share a method or a variable between multiple objects of a class instead of creating separate copies for each object, we use static keyword to make a method or variable shared for all objects.

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

What is data encapsulation and what’s its significance?

A

Encapsulation is a concept in Object Oriented Programming for combining properties and methods in a single unit.

Encapsulation helps programmers to follow a modular approach for software development as each object has its own set of methods and variables and serves its functions independent of other objects. Encapsulation also serves data hiding purpose.

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

What is a singleton class? Give a practical example of its usage.

A

A singleton class in java can have only one instance and hence all its methods and variables belong to just one instance. Singleton class concept is useful for the situations when there is a need to limit the number of objects for a class.

The best example of singleton usage scenario is when there is a limit of having only one connection to a database due to some driver limitations or because of any licensing issues.

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

What are Loops in Java? What are three types of loops?

A

Looping is used in programming to execute a statement or a block of statement repeatedly.
1) For Loops

2) While Loops
3) Do While Loops

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

What is an infinite Loop?

A

An infinite loop runs without any condition and runs infinitely. An infinite loop can be broken by defining any breaking logic in the body of the statement blocks.

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

What is the difference between continue and break statement?

A

When a break keyword is used in a loop, loop is broken instantly while when continue keyword is used, current iteration is broken and loop continues with next iteration.

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

What is the difference between double and float variables in Java?

A

In java, float takes 4 bytes in memory while Double takes 8 bytes in memory. Float is single precision floating point decimal number while Double is double precision decimal number.

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

What is Final Keyword in Java? Give an example.

A

In java, a constant is declared using the keyword Final. Value can be assigned only once and after assignment, value of a constant can’t be changed.

When a method is declared as final,it can NOT be overridden by the subclasses.This method are faster than any other method,because they are resolved at complied time.

When a class is declares as final,it cannot be subclassed. Example String,Integer and other wrapper classes.

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