Tuesday, September 28, 2010

Few fundamental question answers in ICSE BlueJ

Define an object

Object is the instance of a class. Class is the template and object is the real entity which can be used to perform specific type of jobs as defined in the class. An object consists of data members and function / method members. Data member hold values and function members of the object acts on the data members.
Data members may be of primitive type variables or objects of other predefined classes.

What is a method?


Method or function means statement or statements kept within a block. In java block is defined by curly braces [{…}]. A name is assigned to the block which is known as function name. The name must start with any alphabet and by convention, function name starts with lower case character. A function should have a return type which indicates what type of values the function should return to the calling program while invoked. If a function does not return any value, its return type should be ‘void’. The return type may be any primitive type or user defined type, i.e. class. The function name is followed by parenthesis which is known as argument or parameter zone which is utilized to pass values to the function from outside. If a function is defined in such a way that it does not take any value or argument from outside, a blank parenthesis is a must. Function body is executed while invoked. Functions of an object actually define the behaviour of an object.

Can there be objects without having any methods?


We can define a class without methods also. In such case the data members should be either declared with public specifier or default specifier as they are to be accessed from outside the class.
e.g.

class BlueJ
{
int height,width,length;
}

Why are methods so important for the description of objects?


As per encapsulation, methods or functions hide the data members from unauthorized access and it is the methods which manipulates the data members of an object. Normally an object contains number of methods which acts on its data members. Each function is normally assigned different jobs. This concept reduces the complexity of a program and the same time reduces the space complexity of a program.

Simply think about your mobile set. It has number of functions and without knowing the complex working of the functions we simply invoke functions get the desired result.

What is a class?


Class can be defined as user defined new data type. Every programming language has number of predefined types which are known as primitive data types. Data types define the nature and behavious of its instance. For example, a declaration ‘int a;’ denotes that ‘a’ is the instance of the predefined type ‘int’ and ‘int’ defines that ‘a’ can hold whole number of a specific range and different operators like ‘+’,’-‘ etc can act on this variable.
Similarly by defining a class we can create a new type with specific nature and behaviour. After defining the class we can create instance of a class which is known as object.

What is an abstraction?

In program language, abstraction means managing complexity without going in details of any working. In real life also we perform lot of work through abstraction. For example a driver drives the car through abstraction. Using the brake, he can stop the car. The complex gearing arrangement behind this operation is unknown to him.
Similarly in programming language, we can work with a predefined object without knowing the details of its methods and data members. We should know how the methods of the object can be invoked and what would be the result. This is called abstraction.

Can there be multiple abstractions of a real world entity

In real life there is lot of examples on abstraction. During fever we take medicine without knowing how this medicine will work. We operate our television set using the remote without knowing how a simple press on remote button changes the channel.

How are classes and abstraction linked?

In every class, number of methods is defined. These methods use number of data members and act on these data members. While using any object of a predefined class, we simply invoke methods of the object to get our work done without knowing the detail operation of the method. This is abstraction. For example while calling ‘print()’ or ‘println()’ method we know that it will display the argument as a string but the codes executed by these methods to perform the job is not known to us.

What is an object factory?

Class is known as object factory, as after defining any class we can create number of instances of that class. These instances are known as objects. Objects are created following the nature and behaviour defined by the class.

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner