Quiz Space

Java End Term: 3 April 2022, Set AN1 (January 2022 term)

Question 1

+3 marksOne correct option

Consider the Java code given below.

java
import java.io.*;
import java.util.*;
public class FClass{
static boolean writeToFile(String filename) {
try {
FileOutputStream fos = new FileOutputStream(filename);
PrintStream bos = new PrintStream(fos);
bos.println("2 numbers are");
bos.println("3.14 and");
bos.println("10");
return true;
}catch(IOException e) {
return false;
}
}
static boolean readFromFile(String filename) {
try {
FileInputStream fis = new FileInputStream(filename);
Scanner sc = new Scanner(fis);
System.out.println(sc.nextInt());
System.out.println(sc.nextLine());
System.out.println(sc.nextDouble());
System.out.println(sc.nextLine());
return true;
}catch(IOException e) {
return false;
}
}
public static void main(String[] args) throws IOException{
if(writeToFile("E:\\myfile.txt") == false)
System.out.println("write failed");
if(readFromFile("E:\\myfile.txt") == false)
System.out.println("read failed");
}
}

Suppose the file E:\\myfile.txt is written successfully by the program. What will the output be?

  1. A
  2. B
  3. C
  4. D

Question 2

+3 marksOne correct option

The Java code given below produces a checkbox. The initial color of panel pnlColor is blue. If the checkbox is selected, the color of panel pnlColor should become red. Again, if the checkbox is deselected, the color of panel pnlColor should become blue.

java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FClass extends JFrame implements ActionListener{
JCheckBox cbColor;
JPanel pnlColor, pnlBtn;
public FClass(){
setSize(200, 200);
cbColor = new JCheckBox("Red Panel");
cbColor.addActionListener(this);
pnlColor = new JPanel();
pnlBtn = new JPanel();
pnlBtn.add(cbColor);
add(pnlBtn, "South");
add(pnlColor, "Center");
pnlColor.setBackground(Color.blue);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
/*--------------------*/
/*****CODE SEGMENT*****/
/*--------------------*/
}
public static void main(String[] args){
new FClass();
}
}

Choose the correct code segment inside method actionPerformed() such that the execution of the code results in the expected behaviour.

  1. A
  2. B
  3. C
  4. D

Question 3

+3 marksOne correct option

Consider the Java code given below.

java
class Employee{
String name;
int salary;
public Employee(String n, int s){
name = n;
salary = s;
}
public Employee(Employee e){
this.name = e.name;
this.salary = e.salary;
}
public double bonus(){
return salary * 0.1;
}
}
public class Test {
public static void main(String[] args) {
Employee e1 = new Employee("raju",12000);
var e2 = new Employee(e1);
e2.salary = 10000;
System.out.println(e1.bonus());
System.out.println(e2.bonus());
}
}

Choose the correct option.

  1. A
  2. B
  3. C
  4. D

19 more questions in this paper

Sign in with Google — it is free — to see every question with its answer and explanation, practise it in learning mode, or take it as a timed mock test.

More on the Java End Term 3 Apr 2022 Set AN1 paper

The IIT Madras BS Programming Concepts using Java (Java) End Term paper sat on 3 Apr 2022, in the January 2022 term, set AN1: 22 questions for 100 marks in 180 minutes. The first 3 questions are below. Sign in with Google — it is free — to see the whole paper with its answers and explanations, in learning mode or as a timed mock test.

FeatureJava End Term 3 Apr 2022 Set AN1 at a glance
TermJanuary 2022 term
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions22
Marks100
Duration180 min
MCQ14
MSQ8
Official paperIIT M FOUNDATION DIPLOMA ENDTERM FN1 3 Apr 2022
Negative markingNo negative marking.
Updated

Other sets that day

Same End Term, other subjects

More Java