Java Theory QuestionsC10 Class as the Basis of all Computation - Copy
Java Theory QuestionsC10 Class as the Basis of all Computation - Copy
----------------------------------------------------------------------------------------------------------------
4. Give the difference between primitive data type and reference data type with one
example.
Ans.
1
Primitive data type Reference data type
1. The fundamental data types available 1. They are complex data types
with Java are known as primitive constructed by combining primitive
data type. data types.
2. They are defined by Java 2. They are defined by programmers
3. They can store only one vale 3. They can store multiple values either
of same type or multiple
4. Example: int, float, char, double, 4. Example: class, arrays, reference.
long, short, byte, boolean.
Example:
private static final int c_Year = current_year();
public static int current_year(){
return 2019;
}
3. The keyword static is used make a 3. Only primitive data types are used to
variable as class variable. make a variable as instance variable.
4. Example. 4. Example.
class data class data
{ {
static int a; // ‘a’ is class variable. int p, q; // ‘p’ and ‘q’ are instance
} //variable.
}
2
7. What is composite data type? Give an example.
Ans. Group of more than one primitive data type or reference data type as a single unit (Class) is
known as composite data type. A class is known as composite data type.
Example.
class Demo
{
int x;
float m;
char ch;
}
10. What are objects? Why are objects called instance of the class?
Ans. A Java object is a combination of data and procedures working on the available data. The
object has some characteristics and behaviour. An object is instantiated from a class hence it
is also referred to as instance of a class.