Quiz Space

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

Question 1

+3 marksOne correct option

Consider the Java code given below.

java
class Vehicle{
public void mileage(){
System.out.println("Mileage is not known.");
}
public void tyres(){
System.out.println("Number of tyres is not known.");
}
}
class Airplane extends Vehicle{
public void mileage(){
System.out.println("Mileage < 1km/L.");
}
}
class Car extends Vehicle{
public void mileage(){
System.out.println("Mileage >= 10km/L.");
}
public void tyres(){
System.out.println("Number of tyres is 4.");
}
}
public class FClass{
static void compute(Vehicle s){
s.mileage();
s.tyres();
}
public static void main(String[] args){
Vehicle c = new Car();
Vehicle a = new Airplane();
compute(c);
compute(a);
}
}

What will the output be?

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

Question 2

+3 marksOne correct option

Consider the Java code given below.

Suppose the file E:\\test.txt is written successfully by the program.

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("it stores two int");
bos.println("10 is one");
bos.println("20 is another");
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.next());
System.out.println(sc.nextLine());
System.out.println(sc.nextInt());
System.out.println(sc.nextLine());
return true;
}catch(IOException e) {
return false;
}
}
public static void main(String[] args) throws IOException{
if(writeToFile("E:\\test.txt") == false)
System.out.println("write failed");
if(readFromFile("E:\\test.txt") == false)
System.out.println("read failed");
}
}

What will the output be?

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

Question 3

+3 marksOne correct option

The Java code given below produces a toggle button. With the first click of the button, the color of panel pnlColor should become red, with the next click it should become blue, and on the next click, it should turn to red again, and so on. Based on the requirement, answer the question that follows the code.

java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FClass extends JFrame implements ActionListener{
JButton btnToggle;
JPanel pnlColor, pnlBtn;
public FClass(){
setSize(200, 200);
btnToggle = new JButton("Toggle");
btnToggle.addActionListener(this);
btnToggle.setActionCommand("red");
pnlColor = new JPanel();
pnlBtn = new JPanel();
pnlBtn.add(btnToggle);
add(pnlBtn, "South");
add(pnlColor, "Center");
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 given behaviour can be implemented correctly.

  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 FN1 paper

The IIT Madras BS Programming Concepts using Java (Java) End Term paper sat on 3 Apr 2022, in the January 2022 term, set FN1: 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 FN1 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