MSBTE JAVA TOPPER LEVEL ANSWERS
2 MARKS
Q: Logical Operators
A: && (AND), || (OR), ! (NOT)
Q: Constructor
A: Special method used to initialize objects. Same name as class, no return type.
Q: Interface
A: Collection of abstract methods implemented using 'implements'.
4 MARKS
Q: Features of Java
A: Platform Independent, Object-Oriented, Secure, Robust, Multithreaded, Portable, High
Performance, Distributed.
Q: Exception Handling
A: Handled using try, catch, finally, throw keywords to manage runtime errors and avoid program
crash.
Q: Program: Prime Number
A: Checks whether a number is prime.
import [Link].*;
class Prime {
public static void main(String args[]) {
int n=7, flag=0;
for(int i=2;i<=n/2;i++){
if(n%i==0){
flag=1;
break;
}
}
if(flag==0)
[Link]("Prime");
else
[Link]("Not Prime");
}
}
Q: Program: Even numbers 1 to 100
A:
class Even {
public static void main(String args[]) {
for(int i=1;i<=100;i++){
if(i%2==0)
[Link](i);
}
}
}
6 MARKS
Q: Parameterized Constructor
A: Constructor with parameters used to initialize objects with values.
class Student {
int id;
String name;
Student(int i, String n){
id=i;
name=n;
}
void display(){
[Link](id + " " + name);
}
public static void main(String args[]){
Student s1 = new Student(1,"Ali");
[Link]();
}
}
Q: Thread Example (Even & Odd)
A: Two threads printing even and odd numbers.
class EvenThread extends Thread {
public void run() {
for(int i=2;i<=50;i+=2){
[Link]("Even: "+i);
}
}
}
class OddThread extends Thread {
public void run() {
for(int i=1;i<=50;i+=2){
[Link]("Odd: "+i);
}
}
}
class Test {
public static void main(String args[]){
new EvenThread().start();
new OddThread().start();
}
}
EXAM TIPS
1. Always write syntax + example. 2. Programs must be properly indented. 3. Write at least 4-6
points for theory. 4. Use diagrams for full marks. 5. Don't skip keywords like public, static, void.