OOP Flashcards
A ____, in the context of Java, are templates that are used to create objects, and to define object data types and methods. Core properties include the data types and methods that may be used by the object
class
A ____ can also be defined as a blueprint from which you can create an individual object.
class
Any entity that has state and behavior is known as an _____
object
ex. a chair, pen, table, keyboard, bike, etc. It can be physical or logical.
An Object can be defined as an instance of a class.
True or False
True
An _____ contains an address and takes up some space in memory.
Object
OOPs makes development and maintenance easier whereas in a procedure-oriented programming language it is not easy to manage if code grows as project size increases.
True or False
True
In OOPs data can be accessed from anywhere, whereas in a procedure-oriented programming language a global data can be hidden.
True or False
FALSE
OOPs provides data hiding whereas in a procedure-oriented programming language a global data can be accessed from anywhere.
A _____ is a blueprint from which individual _____ are created.
A class is a blueprint from which individual objects are created.
A _________ is called when a instance of the object is created.
constructor
When a constructor is created, _____ is allocated for the object.
memory
When an object is created, compiler makes sure that constructors for all of its subobjects (its member and inherited objects) are called.
True or False
True
A Constructor name does not have to be same same as its class name
True or False
False
Constructor name must be the same as its class name
A Constructor must have no explicit return type
True or False
True
A Java constructor can be abstract, static, final, and synchronized
False
A Java constructor cannot be abstract, static, final, and synchronized
What are the two types of constructors?
- Default Constructor
- Parameterized Constructor
The _____ ________ is a no-args constructor that the Java compiler inserts on your behalf; it contains a default call to super(); which is the default behavior.
default constructor
The following is an example of type of contructor type?
public Bicycle() {
gear = 1;
cadence = 10;
speed = 0;
}
Default Constructor or No-Argument Constructor
Bicycle yourBike = new Bicycle(); invokes the no-argument constructor to create a new Bicycle object called yourBike.
a _____ ________ is added by the compiler when there is no constructor declared in the class.
default constructor
What happens to the following constructor when compiled?
class Bike {
}
class Bike {
Bike(){}
}
A constructor which has a specific number of parameters is called a __________ _________
Parameterized Constructor
This the below class has an example of what type of constructor?
class Student4{
int id;
String name;
Student4(int i,String n){
id = i;
name = n;
}
void display(){System.out.println(id+” “+name);}
public static void main(String args[]){
Student4 s1 = new Student4(111,”Karan”);
Student4 s2 = new Student4(222,”Aryan”);
s1. display();
s2. display();
}
}
parameterized constructor
In Java, a constructor is just like a ______ but without return type.
method
A class cannot be overloaded like a method.
True or False
False
A class can be overloaded
_________ ___________ in Java is a technique of having more than one constructor with different parameter lists.
Constructor overloading
When constructors are overloaded each constructor is setup to perform a seperate task. They are differentiated by the compiler by the number of ________ in the list a and their _____.
When constructors are overloaded each constructor is setup to perform a seperate task. They are differentiated by the compiler by the number of parameters in the list a and their types.
A method must have a return type
True or False
True
The method name may or may not be same as the ____ name.
class
The method is invoked ________
explicitly
The method can be provided by the compiler
True or False
False
The method is not provided by the compiler in any case.
A method is used to _______ the behavior of an object.
expose
A constructor is used to ________ the state of an object.
Initialize
Can a constructor have a return type
True or False
False
A constructor must not have a return type.
The constructor is invoked ______.
implicitly
The Java compiler provides a default _________ if you don’t have any constructor in a class.
constructor
The constructor name must be same as the class name.
True or False
True