Interview Prep Flashcards
What is polymorphism?
Using the same method to do different things eg when extending a class. For example, the Animal class might contain the method makeSound() and the Pig class which extends the Animal class might use the makeSound() method to print “oink” by overriding this method
What are the main features of Java?
portable, robust, secure, platform-independent, OOP language, supports multithread
What is an Array?
All elements have the same data type. Arrays are a fixed same and this size cannot be changed once declared. Accessing an invalid index will cause an exception
Where are Arrays created?
On the heap memory, not on the stack
What is the syntax to create an Array?
dataType[] arrayVariableName = new dataType[arraySize];
Is it possible to create an Array without giving it a size?
No - this will cause a compile-time error
What is a runtime error?
A runtime error occurs when a program does not contain any syntax errors but features a command the computer can not perform, such as dividing by 0
What are the basic principles of OOP?
Abstraction, Encapsulation, Inheritance, Polymorphism
What is abstraction in Java?
Abstraction means hiding the detailed information from the user. Abstraction can be achieved by interfaces and abstract classes.
What is inheritance in Java?
Inheritance allows a Java class or interface to inherit properties and behaviour from another class or interface. Inheritance can be gained by implementing interfaces or extending classes.
What is an object in Java
An object is an instance of a class. A class is a blueprint for an object, containing its basic properties and behaviour. The new keyword is used to instantiate a class and make an object. For example, Animal.java has a class named Animal. Animal animal = new Animal() is an object or instance of this class
What is method overloading?
When a method has the same name but a different number of arguments
Does Java support multiple inheritance?
No, but multiple inheritance can be gained by using interfaces
What is the difference between a method and a constructor?
A constructor is a method within a class with the same name as the class and no return type.
Can the main method be overloaded?
Yes