Back to home

Topics

1. How are variables declared?

General format of declaring variables:

                        data type variable name;    

Example           int a ;
                       int a,b;

2. What are the different known data types?

Primitive data type and composite types are the known data types.

3. What role does a primitive data type play in a java application?

These are the inbuilt data types which serve as the basic types for the derived (reference)types.The reference types are also known as composite data type.

4. What are the different known primitive types?

Primitive data type are :

                    byte, short, int, long, float, double,  char and boolean.

5. Write the storage space reserved for all kinds of integer primitive types

Data Type                         Storage space(in Bytes)         Storage Space (in bits)

byte                                        1 Byte                                    8

short                                       2 Bytes                                  16

int                                           4 Bytes                                  32

long                                        8 Bytes                                  64

6.Write the smallest and largest value for all kinds of integer primitive types.

Integer type                      Smallest Value                       Largest Value

byte                                      -128                                        127

short                                     -32768                                     32767

int                                         -231                                         231-1

long                                      -263                                         263-1

7.How many bits does a boolean type variable reserve for itself ?
 
Boolean type variable reserves 1 bit .

8.How many bits does a double type variable reserve for itself?
 

Double type variable reserves 64 bits (8 Bytes).

9. What are the minimum and maximum numbers that can be accomodate by the following primitive types:

(i) float  (ii)  double  (iii) char

Data type                    Minimum value            Maximum value

float                                3.4×10-38                     3.4×1038

double                            1.7×10-308                    1.7 ×10308

char                               0                                   65536

10. Why is a class known as composite data type ?
  
A class binds up  and hence encapsulates one or more primitive types together to be  used as a single unit ( data type) .Hence ,it is called composite data type.

11. Why is a class known as user-defined data type ?

The design of the class is decided by the programmer according to his programs need.Hence it is called user defined data type.

12. How much storage space does a class type variable reserve for itself ?

A class type variable (which is an object) reserves the sum total of the storage space(in bits/bytes) occupies by each of the member variable.

For example,

class Abc
{
     int a;
   float b;
   void function 1( )
   {
   a=5; b=10;
   system .out.printIn(a);
   system . out.print(b);
    }
}

An object of above class Abc will occupy 4 Bytes for its integer variable a and 4 Bytes for its float variable b. In total 8 Bytes is reserved for the object variable of class Abc.

13.How is a class type variable declared?
    
Declaration or creation of class type variable (object).

Creating  object of a class .

General format 1 :

className objectName = new className( );

Example :

                Complex Number num = new ComplexNumber();

General format 2 :

className objectName;

Example :

               classNumber num;

              num=new ComplexNumber( ) ;

14. What is this class type variable called ?
    
The class type variable is called object of the class.

15. What role does a class play in a java application ?
     
An application program in java is also called stand alone application program .It  uses the resources of a single computer system and all its statements are embedded in a class.Thus ,it is impossible to create a java program without making use of a class.

16. What role do the variables of class type(objects) play in a java application ?

    
The attributes of objects of the class are defined in the class architecture .Thus a class represents a general prototype (model) of all the objects it can create .These objects (variables of the class type) have their own identity .The methods of the class can be called by each of such object and hence separate execution of each objects function may take

17. Write the differences in a primitive type and a composite data type .
    

A primitive data type is an inbuilt simple type of java.The number of bits occupied by each of such primitive type is fixed and cannot be altered by the programmer .

A composite data type is defined by a programmer himself in his program himself in his program.It comprises of one or more primitive types.The primitive data type and the number of variables of each type decides the number of bits/bytes reserved for a composite type (class).

18. Illustrate the above difference through examples.
    
Example of primitive data type:     

              int for which 4 Bytes = 4 ×8 =32 bits are reserved .

Example of composite data type

           class Complex
           {
                     int a ;
                     double b ;
            }

a requires 32 bits and b requires 64 bits.So ,composite type Complex requires 64+32=96 bits for each of its object.

19. Name all possible members of a class.

Members of a class can be :

(a) Data members : They are also called member variables or instance variables.In general terms ,attributes (or characteristics) of an object are represented in the form of member variables in a program .

(b) Constructions : These are a kind of functions used to initialise values to the member variables

(c) Methods : These are the functions ,also called Member functions .They are used to apply a process on the objects attributes .

20. Can any primitive type be a class member variable .


Yes ,all primitive types are allowed to be used a member variables .

21. What is the different between a member variable and a local variable?
    
A member variable is declared in a class outside all functions( even main) It can be accessed anywhere in the class.It acquires different values for different objects .But if it is a static member variable ,it acquires a single value for each object and hence should not be associated with an object.

A local variables is a variable declared in the body of a function .Hence,its scope is limited to the function body.It cannot be accessed in any other function.It must not be associated with an object as it does not represent the attribute of an object.

22. What is the need of a constructor as a class member?

A constructor is needed to initialise values of member variables.

23. What is the need of a method as a class member?

A method is needed to apply process on the object's variables.

24. How can a class type variable support the accessing of members of a class ?

Class members can be accessed through class type variables (object) by the use of a dot(.) operator .e.g.,object .member function ( );

25. Can another class be a member of a class ?

Yes,a class may contain another class,Such a structure is called nested classes.

26. How can a class type provide security to the members that it wraps?

A class encapsulates the data members and the member functions.The security is provided by the access specifiers.They check the use of members outside the class.

27. What are the different keywords that check the visibility of a member of the class ? What are they called ?

The keywords are:Public ,protected and private.They are called visibility modifiers or access specifiers.

28. How does a public ,private and protected specifiers differ in the members visibility.

A public variable or method can be accessed in any class / sub - class outside the class in which it is defined .It has the widest visibility .

A private variable or method is highly protected as it can be accessed only within the class in which it is defined .

A protected variable or method is visible to all classes and sub-classes in the same package and the sub - classes in other packages.

29. When do we call a class as an application program?

When the class contain the main method .It is called an application program.As main is the first method to get executed in the program.All other methods may be called from main .

Paid Users Only!
Paid Users Only!
Paid Users Only!
Paid Users Only!
Paid Users Only!
Paid Users Only!
Paid Users Only!
Paid Users Only!
Paid Users Only!
Paid Users Only!
Paid Users Only!
Paid Users Only!
Paid Users Only!
Powered By