adplus-dvertising

Welcome to the Data Types,Variables and Arrays MCQs Page

Dive deep into the fascinating world of Data Types,Variables and Arrays with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Data Types,Variables and Arrays, a crucial aspect of Java Programming. In this section, you will encounter a diverse range of MCQs that cover various aspects of Data Types,Variables and Arrays, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Java Programming.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Data Types,Variables and Arrays. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Java Programming.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Data Types,Variables and Arrays. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Data Types,Variables and Arrays MCQs | Page 12 of 32

Explore more Topics under Java Programming

Q111.
What will be the output of the program?

public class ArrayTest 
{ 
    public static void main(String[ ] args)
    { 
        float f1[ ], f2[ ]; 
        f1 = new float[10]; 
        f2 = f1; 
        System.out.println("f2[0] = " + f2[0]); 
    } 
}
Discuss
Answer: (a).It prints f2[0] = 0.0
Q112.
What will be the output of the program?

class Super 
{ 
    public Integer getLength() 
    {
        return new Integer(4); 
    } 
} 

public class Sub extends Super 
{ 
    public Long getLength() 
    {
        return new Long(5); 
    } 

    public static void main(String[] args) 
    { 
        Super sooper = new Super(); 
        Sub sub = new Sub(); 
        System.out.println( 
        sooper.getLength().toString() + "," + sub.getLength().toString() ); 
    } 
}
Discuss
Answer: (d).Compilation fails.
Q113.
What will be the output of the program?

class A 
{
    final public int GetResult(int a, int b) { return 0; } 
} 
class B extends A 
{ 
    public int GetResult(int a, int b) {return 1; } 
} 
public class Test 
{
    public static void main(String args[]) 
    { 
        B b = new B(); 
        System.out.println("x = " + b.GetResult(0, 1));  
    } 
}
Discuss
Answer: (c).Compilation fails.
Q114.
What will be the output of the program?

public class Test 
{  
    public static void main(String args[])
    { 
        class Foo 
        {
            public int i = 3;
        } 
        Object o = (Object)new Foo();
        Foo foo = (Foo)o;
        System.out.println("i = " + foo.i);
    }
}
Discuss
Answer: (a).i = 3
Q115.
What will be the output of the program?

public class A
{ 
    void A() /* Line 3 */
    {
        System.out.println("Class A"); 
    } 
    public static void main(String[] args) 
    { 
        new A(); 
    } 
}
Discuss
Answer: (d).The code executes with no output.
Q116.
What will be the output of the program?

class Super
{ 
    public int i = 0; 

    public Super(String text) /* Line 4 */
    {
        i = 1; 
    } 
} 

class Sub extends Super
{
    public Sub(String text)
    {
        i = 2; 
    } 

    public static void main(String args[])
    {
        Sub sub = new Sub("Hello"); 
        System.out.println(sub.i); 
    } 
}
Discuss
Answer: (d).Compilation fails.
Q117.
What will be the output of the program?

public class Test 
{
    public int aMethod()
    {
        static int i = 0;
        i++;
        return i;
    }
    public static void main(String args[])
    {
        Test test = new Test();
        test.aMethod();
        int j = test.aMethod();
        System.out.println(j);
    }
}
Discuss
Answer: (d).Compilation fails.
Q118.
Which two code fragments inserted at end of the program, will allow to compile?

1. class AllMath extends DoMath { double getArea(int r); }
2. interface AllMath implements MathPlus { double getVol(int x, int y); }
3. interface AllMath extends DoMath { float getAvg(int h, int l); }
4. class AllMath implements MathPlus { double getArea(int rad); }
5. abstract class AllMath implements DoMath, MathPlus { public double getArea(int rad) { return rad * rad * 3.14; } }
interface DoMath 
{
    double getArea(int rad); 
}
interface MathPlus 
{
    double getVol(int b, int h); 
}
/* Missing Statements ? */
Discuss
Answer: (c).3 and 5
Q119.
Which two statements are true for any concrete class implementing the java.lang.Runnable interface?

1. You can extend the Runnable interface as long as you override the public run() method.
2. The class must contain a method called run() from which all code for that thread will be initiated.
3. The class must contain an empty public void method named run().
4. The class must contain a public void method named runnable().
5. The class definition must include the words implements Threads and contain a method called run().

The mandatory method must be public, with a return type of void, must be called run(), and cannot take any arguments.
Discuss
Answer: (d).2 and 6
Q120.
Which two statements, added independently at beginning of the program, allow the code to compile?

1. No statement is required
2. import java.util.*;
3. import.java.util.Tree*;
4. import java.util.TreeSet;
5. import java.util.TreeMap;
/* Missing statements ? */
public class NewTreeSet extends java.util.TreeSet
{
    public static void main(String [] args) 
    {
        java.util.TreeSet t = new java.util.TreeSet();
        t.clear();
    }
    public void clear() 
    {
        TreeMap m = new TreeMap();
        m.clear();
    }
}
Discuss
Answer: (b).2 and 5

Suggested Topics

Are you eager to expand your knowledge beyond Java Programming? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!