Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
2Activity
0 of .
Results for:
No results containing your search query
P. 1
MCS-024

MCS-024

Ratings: (0)|Views: 13 |Likes:
Published by kktamang09

More info:

Published by: kktamang09 on Apr 13, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

02/09/2011

pdf

text

original

 
MCS
-
024 Object
Oriented Technologies and Java
Programming
 
__________________________________________________________________________
 Course Code : MCS-024Course Titlle :
Object Oriented Technologies and Java
 ProgrammingAssignment Number : MCA (1)/024/Assign/09
__________________________________________________________________________
 
Q1.
(a)
What is Object Orientation? Explain the advantage of object Orientation ?
Ans
a)
:
In
(object
-
oriented) programming, code and data are merged into a single indivisible thing
--
an object. Objects are individual
instances 
of a class. For example, you may create an object callSpot from class
Dog.
The Dog class defines what it is to be a Dog object, and all the "dog
-
related" messages a Dog object can act upon. All object
-
oriented languages have some means,usually called a
factory 
, to "manufacture" object instances from a class definition.
 
Object
-
oriented programming takes the view that what we really care about are the objects we
want to man
ipulate rather than the logic required to manipulate them. Examples of objects rangefrom human beings (described by name, address, and so forth) to buildings and floors (whoseproperties can be described and managed) down to the little widgets on your com
puter desktop(such as buttons and scroll bars).
 
One of the principal advantages of object
-
oriented programming techniques over procedural
programming techniques is that they enable programmers to create modules that do not need to
be changed when a new
type of object is added. A programmer can simply create a new objectthat inherits many of its features from existing objects. This makes object
-
oriented programseasier to modify.
 
 
Q2
b) What are different relational operators in Java? Write a Java pr
ogram to explain the
use
of relational operators
?
 
Ans :Programme :
 
public class marks
 {
static int stud1;
 
public marks(int a)
 
{
 
stud1=a;
 
}
public void grade()
 
{
 
i
f
(
(stud1>70)&&(stud1<100))
 
System.out.println(“Grade A”);
 
else
 
if((stud1>50)&&(stud1<70))
 
System.out.println(“Grade B”);
 
else
 
System.out.println(“Fail”);
 
}
 
public static void main(String args[])
 
{
 
marks m1=new marks(80);m1.grade();
 
}
 
}
 
The symbols
&&
and
||
are the logical
AND
and
OR
operators used to evaluate logical
ex
pressions. Use
&&
and
||
in the evaluation of compound expressions of the form
 
·
 
expression_1 && expression_2
 
where expression_1 and expression_2 each evaluate to a scalar, logical result.
 
The
&&
and
||
operators support short
-
circuiting. This means that the second operand is valuated
only when the result is not fully determined by the first operand
 
Q :4)
 a) What is Interface in Java ?
Why abstract classes are used in inheritance?
Write aProgram in Java to Explain interface and Multiple Inheritance in Java?
Ans : Methods form the object's
interface
with the outside world; the buttons on the frontof your television set, for example, are the interface between you and the electrical wiringon the other side of its plastic casing. You press the "power" button to turn the television
on and off. In its most common form, an interface is a group of related methods with
empty bodies. A bicycle's behavior, if specified as an interface, might appear as follows:
interface Bicycle {
 
 
 
void changeCadence(int newValue);
 
void changeGear(int newValue);
 
void speedUp(int increment);
 
void applyBrakes(int decrement);
 
}
 
To implement this interface, the name of your class would change (to
ACMEBicycle, forexample), and you'd use the implementskeyword in the class declaration:class ACMEBicycle
implements
Bicycle {
 
 // remainder of this class implemented as before
 
}
 
we can create a class by extending from more than one class. It is problematic. So in Java thisfeature is eliminated. Anyway for getting multiple inheritance, Java introduced the concept ofinterfaces. So we can create a class by extending one class or we can implement any number ofinterfaces for it. But the restriction is we have to implement / descr
ibe every method existing inthe interfaces
 
b)
What is a Constructor ?Explain the need of constructors overloading in Java
Programme ?
Ans :
The constructor method is called when a new instance of an object is created. Constructors
and methods differ i
n three aspects of the signature: modifiers, return type, and name. Like
methods, constructors
can have any of the access modifiers: public, protected, private, or none
(often called
package 
or
friendly 
).
Unlike methods, constructors can take only access modifiers.Therefore, constructors cannot be abstract
,
final
,
native
,
static, or
synchronized
.
Overloading is a powerful feature, but you should use it only as needed. Use it when you actuallydo need multiple methods with different parameters, but the met
hods do the same thing
.
Q 5)
a) What is an exception? Explain different types of exceptions in Java.
Also explainhow an exception subclass are created, in Java. 
Ans :
E
xceptions are the customary way in Java to indicate to a calling method
that an abnormal
condition has occurred.When a method encounters an abnormal condition (an
exception condition 
) that it can't handle itself, it may
throw 
an exception. Throwing an exception is likethrowing a beeping, flashing red ball to indicate there is a problem that can't be handled where itoccurred. Exceptions are
caught 
by handlers positioned along the thread's method invocationstack.
 
Exceptions are 2 types.
 
1.Checked
 
2.Uncheked
 
All the exception for that compiler doesn't care are comes under unch
ecked exception i.e.ArithmaticException, ArrayIndexOutofBoundexp etc
 

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->