Sample Questions – Self Practice
(LBJ Module 3 – Java Basics)
Q.1) Which keyword is used to inherit a class?
Q.2) What is the difference between class and an interface?
Q.3) What is the benefit of constructor in a class?
Q.4) What is Unicode and which datatype of Java supports Unicode?
Q.5) What are some of the naming conventions that we follow in any Java program?
Q.6) What will be the output of below Java program:
class CharTest {
public static void main(String args[]) {
char ch1, ch2;
ch1 = 65;
ch2 = 'B';
System.out.println(ch1 + ' ' + ch2);
}
}
Q.7) What will be the output of below Java program:
class Super {
public int index = 1;
}
class App extends Super {
public App(int index) {
index = index;
}
public static void main(String args[]) {
App myApp = new App(10);
System.out.println(myApp.index);
}
}
Q.8) What will be the output of below Java program:
class PC {
String memory = "1GB";
}
class Workshop {
public static void main(String args[]) {
PC dell = new PC();
repair(dell);
System.out.println(dell.memory);
}
public static void repair(PC pc) {
pc = new PC();
pc.memory = "2GB";
}
}
Q.9) What will be the output of below Java program:
class MyStringDemo {
public static void main(String[] args) {
String str1 = "LTI";
String str2 = str1;
str1 = "LTI Mumbai";
if(str1==str2) {
System.out.println("Both String objects are equal");
}else {
System.out.println("Both String objects are NOT equal");
}
}
}
Q.10) Write a Java program that converts a positive integer into the Roman number system.
The Roman number system has digits:
I=1
V=5
X = 10
L = 50
C = 100
D = 500
M = 1,000