(XXXX) 2 Marks (XXXX) : - Class B Extends A
(XXXX) 2 Marks (XXXX) : - Class B Extends A
1.
class Building
{
Building()
{
System.out.println("Building");
}
Building(String name)
{
this();
System.out.println(“Building: String Constructor" + name);
}
}
public class House extends Building
{
House()
{
System.out.println("House ");
}
House(String name)
{
this();
System.out.println("House: String Constructor" + name);
}
public static void main(String[] args)
{
new House("XYZ");
}
}
• Java.lang.class
• Java.class.inherited
• Java.class.object
• Java.lang.object
(C)What is the use of “this” method in above code ?
• This is used to initialize constructor
• This keyword refers to the parent object
• This keyword refers to the current object
• None
(D)What would be result if a class implements two interfaces and both have a method with same name
and signature? Lets assume that the class is not implementing that method.
• Runtime Error
• Compile time error
• Codes run successfully
• First call method is executed sucsessfully
(E) What is the output of above code?
2. (2 Marks)
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();
}
}
• Packages
• Nested Packages
• Util subpackages
• Subpackages
(B)What is the correct output of program?
• 012
• Compile time error
• 0
• 2
(C) Which of the following package stores all the standard java classes?
• Lang
• Java
• Java.packages
• Util
(D)What will be the output if if(x>1) will be changed as if (x<1) ?
• 012
• 2
• 0
• Compile time error
(E)What will be result if both for loop will be changed to for (int i=0;i>3;i++) ?
• Java.lang.NullpointerException
• 012
• Run time error
• 0
3.
class demo
{
int a, b;
demo()
{
a = 10;
b = 20;
}
public void print()
{
System.out.println ("a = " + a + " b = " + b + "\n");
}
}
class Test
{
obj1.a += 1;
obj1.b += 1;
}
}
(C)In order to restrict a variable of a class from inheriting to subclass. How variables should be declared? (2 Marks)
• Protected
• Private
• Public
• Static
(D)When object of class initialized, then which constructer to be called? (2 Marks)
• Copy constructer
• Default Constructor
• Parameterized Constructor
• None of these
4.
import java.io.*;
interface ln1
{
final int a = 10;
void display();
}
class TestClass implements ln1
{
public void display()
{
System.out.print("java");
}
public static void main (String[] args)
{
TestClass t = new TestClass();
t.display();
System.out.println(a);
}
}
(A)Guess the result of your program if object creation will be like TestClass t= new ln1(); ? (2 Marks)
• Java 10
• In 1 is abstract; cannot be instantiated
• Runtime Error (NOT CONFIRM)
• Null
(C).What will be the output if value of a variable will be changed from 10 to 20 in child class? (2 Marks)
• Java 20
• Compile Time Error
• 20 (SORRY)
• Runtime error
5.
class Matrix{
public static void main(String args[]){
int a[][]={{1,3,4},{2,4,3},{3,4,5}};
int b[][]={{1,3,4},{2,4,3},{1,2,4}};
int c[][]=new int[3][3];
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
c[i][j]=a[i][j]+b[i][j];
System.out.print(c[i][j]+" ");
}
System.out.println();//new line
}
}}
(A)If I want to add String b[][]={{“priya”, ”teena” , “niti”}, {“reema”, “shruti” , “grany”} , { “tipsy”, “shainy”, “amrita”}}
with array a then What will be the result?
• Runtime Error
• Compile Time Error
• 1+priya 3+teena 4+niti 2+reena 4+shruti 3+granny 3+tipsy 4+shainy 5+amrita
• 1priya 3teena 4niti 2reema 4shruti
(B) What will be the output if instead of system.out.println(c[i][j]+” “) if system.out.println(c) is to be used out?
• Hashcode
• 468268469
• Compile time error
• Runtime Error
(C)What is the correct output of program?
• 268486469
• 268468469
• 268 469 486
• 468268469
(D)What will be the output if instead of for(int j=0;j<3;j++), for (int j=0; j>3; j++) will be used out?
• No output
• Compile Time Error
• Runtime Error
• 268469486
(E) If I want to add int b[][] ={{1,3,4}, {2,4,3}} with array a then what will be the output?
• Runtime Error
• Compile time error
• ArrayIndexOutofBoundsException (correct solution)
• Syntax Error
6.
Abstract class A {
Abstract void callme();
void callmetoo() {
System.out.println("This is a normal method.");
}}
class B extends A {
void callme() {
}}
class XYZ {
obj.callme();
obj.callmetoo();
}}
class ABC
{
public static void main(String args[])
{
int x = 2;
int y = 0;
for ( ; y < 10; ++y)
{
if (y % x == 0)
continue;
else if (y == 8)
break;
else
System.out.print(y + " ");
}
}
}
8.
class conversion {
public static void main(String args[])
{
double a = 295.04;
int b = 300;
byte c = (byte) a;
byte d = (byte) b;
System.out.println(c + " " + d);
}
}
(D) Which of these is necessary condition for automatic type conversion in java?
• The destination type is smaller than source type
• The destination type is larger than source type
• The destination type can be larger or smaller than source type
• None of the mentioned
(E)What is the range of bytes data type in java ?
• ( -128 to 127)
• -32768 to 32767
• (-2147483648 to 2147483647)
• None of the mentioned