My Report

Java Programming Practice Test 9


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Which of these keywords is used to define interfaces in Java?

2. What will be the output of the following Java code?

public class Shape 
{
	public int area()
        {
		return 1;
	}
}
public class Square extends Shape 
{
	public int area()
        {
		return 2;
	}
}
public class Rectangle extends Shape 
{
	public int area()
        {
		return 3;
	}
}
class Main() 
{
       public static void main(String[] args)
       {
	 Shape shape = new Shape();
	 Square square = new Square();
   	 Rectangle rect = new Rectangle();
	 rect = (Rectangle)square;
	 System.out.println(square.area());
	}
}

3. Which of the below is false about java coding?

4. What will be the output of the following Java program?

   
    package pkg;
    class display 
    {
        int x;
        void show() 
        {
            if (x > 1)
                System.out.print(x + " ");
        }
    }
    class packages 
    {
        public static void main(String args[]) 
        {
            display[] arr=new display[3];
            for(int i=0;i<3;i++)
                arr[i]=new display();
            arr[0].x = 0;      
            arr[1].x = 1;
            arr[2].x = 2;
            for (int i = 0; i < 3; ++i)
                arr[i].show();
         }
    }

Note : packages.class file is in directory pkg;

5. What data structure should be used when number of elements is fixed?

6. What is Optional object used for?

7. Which of the following methods hits database always?

8. Which of the following is the correct way of importing an entire package 'pkg'?

9. Can “abstract” keyword be used with constructor, Initialization Block, Instance Initialization and Static Initialization Block.

10. Which of the following package stores all the standard java classes?


 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.