Q. Which is not a valid statement based on given code?
class A{}
class B extends A{}
Q. What can be said about the statement y = (Sub) x
, based on given code?
// Class declarations :
class Super {}
class Sub extends Super {}
// Reference declarations :
Super x;
Sub y;
Q. Which letters will be printed when the given program is run?
public class MyClass
{
public static void main(String[] args)
{
B b = new C();
A a = b;
if (a instanceof A) System.out.println("A");
if (a instanceof B) System.out.println("B");
if (a instanceof C) System.out.println("C");
if (a instanceof D) System.out.println("D");
}
}
class A {}
class B extends A {}
class C extends B {}
class D extends C {}
Q. Based on the code which of the following statement is correct.
class A
{
B b;
}
class B{}
Q. What will be the Output?
class Animal
{
String name = "animal";
String makeNoise() { return "generic noise"; }
}
class Dog extends Animal
{
String name = "dog";
String makeNoise() { return "bark"; }
}
public class Test
{
public static void main(String[] args)
{
Animal an = new Dog();
System.out.println(an.name+" "+an.makeNoise());
}
}
Q. super keyword in Java is used for?
Q. Which statement is not correct about an overriden method?
public class Test { }
Q. What will be the Output?
class A
{
public void m1()
{ System.out.println("A"); }
}
public class B extends A
{
void m1()
{ System.out.println("B"); }
public static void main(String []args)
{
A a = new B();
a.m1();
}
}
Q. Which operator is used to check object-type at runtime?
Q. Argument passed to a program at the run time is stored in __________.
Q. Predict Output, if the below code is run with given command?
Command Line : java myprog good morning everyone
public class myprog
{
public static void main(String argv[])
{
System.out.println(argv[1])
}
}
Q. Parent class reference variable refers to Child class object, it is known as?
Q. Multiple inheritance is not supported in Java because?