Re: Java Interview Questions
1. What is the difference between Assignment and Initialization?
- Assignment can be done as many times as desired whereas initialization can be done only once.
2. What is OOPs?
- Object oriented programming organizes a program around its data, i. e. , objects and a set of well defined interfaces to that data. An object-oriented program can be characterized as data controlling access to code.
3. What are Class, Constructor and Primitive data types?
- Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char.
4. What is an Object and how do you allocate memory to it?
- Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.
5. What is the difference between constructor and method?
- Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.
6. What are methods and how are they defined?- Methods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes. Method definition has four parts. They are name of the method, type of object or primitive type the method returns, a list of parameters and the body of the method. A method’s signature is a combination of the first three parts mentioned above.
|