Professional Documents
Culture Documents
__________________________________________________________________________
Course Code : MCS-024
Course Titlle : Object Oriented Technologies and Java
Programming
Assignment Number : MCA (1)/024/Assign/09
__________________________________________________________________________
Object-oriented programming takes the view that what we really care about are the objects we
want to manipulate rather than the logic required to manipulate them. Examples of objects range
from human beings (described by name, address, and so forth) to buildings and floors (whose
properties can be described and managed) down to the little widgets on your computer desktop
(such as buttons and scroll bars).
Programme :
public marks(int a)
{
stud1=a;
}
public void grade()
{
if((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”);
}
}
}
The symbols && a n d || are the logical AND a n d OR operators used to evaluate logical
expressions. Use && and || in the evaluation of compound expressions of the form
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 a
Program 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 front
of your television set, for example, are the interface between you and the electrical wiring
on 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);
we can create a class by extending from more than one class. It is problematic. So in Java this
feature is eliminated. Anyway for getting multiple inheritance, Java introduced the concept of
interfaces. So we can create a class by extending one class or we can implement any number of
interfaces for it. But the restriction is we have to implement / describe every method existing in
the interfaces
Ans : The constructor method is called when a new instance of an object is created. Constructors
and methods differ in 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 actually
do need multiple methods with different parameters, but the methods do the same thing.
Ans : Exceptions 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 like
throwing a beeping, flashing red ball to indicate there is a problem that can't be handled where it
occurred. Exceptions are caught by handlers positioned along the thread's method invocation
stack.
1.Checked
2.Uncheked
All the exception for that compiler doesn't care are comes under unchecked exception i.e.
ArithmaticException, ArrayIndexOutofBoundexp etc
Exceptions which needs to be defined in throws clause of a method r checked exception ,ie.
sevletException,ClassNotFoundExp,NoSuchFieldException etc
Ans : The ability of an operating system to execute different parts of a program, called threads,
simultaneously. The programmer must carefully design the program in such a way that all the
threads can run at the same time without interfering with each other.
Example
public class MyT implements Runnable
{
public void run()
{
… // work for thread
}
}
Thread t = new Thread(new MyT()); // create thread
t.start(); // begin running thread
… // thread executing in parallel
Example
public class MyT extends Thread
{
public void run()
{
… // work for thread
}
}
MyT t = new MyT(); // create thread
t.start(); // begin running thread
Q7. b)What is Layout Manager ?Explain Different Layout managers available in java.
Ans: In programming of graphical user interfaces, an object that controls the size and position of
Java components within a container. When placing components into containers in a graphical
user interface, an object called a layout manager may be associated with the container and will
implement a policy for deciding how the components are positioned and sized within the
container.
FlowLayout
The FlowLayout manager is the simplest of the layout managers. In this scheme, components are
arranged in the order they are placed within the container. If a row becomes completely filled, the
remaining components are grouped together on the next row.
BorderLayout
The BorderLayout manager arranges components within specified regions of a container. Valid
regions are "North", "South", "East", "West", and "Center"
GridLayout
A container using the GridLayout scheme arranges components in rows and columns in row-
major order.