Core Java Questions Flashcards
Explain each keyword in public static void main(String args[])?
a. This is the method that is called by the JVM when starting a program
b. Public - is an access modifier that says that this method is accessible by any class
c. static - says that this method can be accessed without instantiating a class
d. void - the method returns no value
e. String args[] - contains command line arguments that can be passed while running the program
What is an object and what is a class
a. Class - is the template or blueprint through which we can create objects in our programs
b. Object - is an instance of a class that represents an entity that the program is trying to model
What is static in Java
a. Keyword that is used for memory management
b. Can be used with classes, variables, methods and block
c. Static members belong to the class instead of a specific instance
d. Static means one per class
What is a constructor?
a. A special method that is used to instantiate an object
b. It has the same name as the class it is declared in
c. It has no explicit return type
d. It can be overloaded.
Types of constructors
a. Default Constructor - when it has no params and provides default values to the properties of the object
b. Parametized Constructor - used to provide different values to the properties of an object when instantiated
What is this keyword
a. can be used to refer to the current class instance variable
b. can be used to invoke current class method
c. this() can be used to invoke current class constructor
d. can be passed as an argument in the method call
e. can be passed as argument in the constructor
d. can be used to return the current class instance from the method.
What is meant by the local variable and the instance variable
a. Local variable - is a variable that is declared inside a method
b. instance variable - is declared inside a class but outside a method
What is inheritance
a. Process by which a class gains the properties and methods of another class.
What is encapsulation
a. Process of hiding implementation details from other classes.
What is polymorphism
a. The ability to perform an action in several different ways
b. There are two type - Static(compile) time polymorphism and dynamic(runtime) polymorphism
What is method overloading
a. When a class has more than one method with the same name but different signature(different parameters)
What is method overriding
a. When a method of a superclass is inherited by a subclass and the implementation is changed.
What are the different access modifiers
a. Access modifiers - are keywords used to set the visibility of classes, constructors and data members
b. Default - visible only within the package
c. Private - visible within the class only
d. Protected - visible within the package and subclasses
e. Public - visible to all classes within or outside the package
What is an Interface
a. An interface is used to achieve abstraction and loose coupling
b. In Java, a class cannot extend more than one class but with interfaces, a class can implement as many interfaces as possible.
c. interfaces have methods that are abstract by default but have no implementation
d. They can also have variables which can be public, static and final by default.
What is an Abstract Class?
a. A class that is declared using the keyword abstract
b. It can have methods that don’t have a body (abstract) as well as concrete methods(those with a body)
c. An abstract class cannot be instantiated but it must be extended to use the abstract and non abstract methods