Android Interview
June 6, 2024 · View on GitHub

Object-Oriented Programming
OOP serves as the basis of Android app development, and be prepared for interviewers to evaluate your expertise in this area.
-
Name some of the characteristics of OOP languages
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
-
What are the access modifiers you know? What does each one do?
public(by default in Kotlin): is widely used on classes, variables, constructors, and methods to grant access from any class and method anywhere.private(by default in Java): variables, methods, constructors, or inner classes are only visible to its' containing class and its' methods.protected: can be used on variables, methods, and constructors therefore allowing access only to subclasses and classes that are inside the same package as protected members' class.internal(just Kotlin): means that any client inside this module who sees the declaring class sees its internal members.
-
What is the difference between overriding and overloading a method in Java?
- Overload: is one method with different signatures and input parameters
- @Override: occurs when a subclass (child class) has the same method or property as the parent class
-
Can an Interface/Class extend another/multiple Interfaces?
- An interface can extend multiple interfaces.
- A single class can implement multiple interfaces, but only one abstract class.
-
What does the static word mean in Java?
- static members belong to the class instead of a specific instance.
-
Can a static method be overridden in Java?
- Static methods cannot be overridden because they are not dispatched on the object instance at runtime.
-
Can a constructor be inherited?
- Constructors are not members of classes and only members are inherited.
-
What are the types of GoF (Gang of Four) design patterns? Provide examples.
- Creational
- Structural
- Behavioral
-
Which Design Patterns are you familiar with?
- Creational patterns
- Builder
- Factory
- Singleton
- Monostate
- Fluent Interface Pattern
- Structural patterns
- Adapter
- Decorator
- Facade
- Behavioural patterns
- Chain of responsibility
- Iterator
- Observer
- Strategy
- More to read: https://refactoring.guru/design-patterns
- Creational patterns
-
Which design patterns are used in Android?
View Holderuses SingletonIntentorToast.makeText()uses FactoryBroadcast Receiveruses ObserverViewuses Composite- Media FrameWork uses Façade
Adapteruses adapter
- Composition is a design principle where a class is composed of one or more objects of other classes, signifying a “has-a” relationship
- Inheritance is a mechanism where a class extends another class, representing an “is-a” relationship
- Using the is-a vs has-a rule, we can determine which one to use. For example: a cat is an animal, but a person has a job.
- Single Responsibility Principle:
- A class should have only a single responsibility (i.e. only one potential change in the software’s specification should be able to affect the specification of the class
- One chef cannot run the whole restaurant!
-
Open / Closed Principle:
- Any software entity (module/class/method) should be open for extension but closed for modification.
- Trying new shoes doesn’t require you to saw your feet off!
- Liskov Substitution Principle:
- Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program
- Interface Segregation Principle:
- Clients should not be forced to depend upon the interfaces that they do not use.
- Many client-specific interfaces are better than one general-purpose interface.
- Dependency Inversion Principle:
- The high-level module must not depend on the low-level module, but they should depend on abstractions. One should “Depend upon Abstractions. Do not depend upon concretions.
- Program to an interface, not to an implementation.
- You wouldn’t wire a lamp directly to your house!
- To avoid the constructor's multiple implementations for setting different fields in a class having many properties.