Professional Documents
Culture Documents
1. To successfully overload a method in Java,the return types -> Does not Matter.
2. class X
{
int i;
public void display()
{
System.out.println(i);
}
}
class Y extends X
{
int j;
public void display()
{
System.out.println(j);
}
}
class m2
{
public static void main(String args[]){
Y obj2 = new Y();
obj2.i = 3;
obj2.j = 7;
X r;
r=obj2;
r.display();
}
}
//ans: 7
3. class m3
{
public static void main(String args[])
{
String s1 = "Dog";
String s2 = "Dog";
String s3 = new String("Dog");
System.out.println(s1 == s2);
System.out.println(s1 == s3);
}
}
Ans :- truefalse
4. class A {
Void show(int a,char b){
System.out.println(“Ding Dong”);
}
void show(char a,int b) {
System.out.println(“Ting Tong”);
}
}
Class B
{
public static void main(String args[]) {
A obj = new A();
obj.B();
}
}
Ans:- No Error.
5.public class A
{
Int info()
{
System.out.println(“CAR”);
return 0;
}
void info()
{
System.out.println(“ROAD”);
}
}
class Main() {
Public static void main(String args[]) {
A a = new A();
Int a = m.info();
}
}
Ans:- Class error
1.A java file may contain-> 1 package statement and then multiple import statements.
2.Interface in java helps to achieve the effect of multiple inheritance.
3.By creating packages in java,we-> Can achieve encapsulation.
4.An abstract class may have-> Abstract method and complete method.
5.A class extending an abstract class may not remain a method ->abstract itself.
6.One program can be divided into or can combine multiple packages.
7.A java file may contain multiple statements and then multiple import statements.
8.Not possible in java:- We can overload and override two different methods in one class where inheritance is
not there.
9.A java file may contain multiple non-public class,but at most one public class.
10.class A, class B extends A, class C extends B,class D extends C.
CA4
1.Which among these access specifiers can be used for a class member so that it can be accessed by a
subclass in a different package? -> Private.
2.What is the effect of the final keyword? ->All of the above.
3.Exception and Error are immediate subclasses of a class called Throwable
4.Which among these access specifiers can be used for a class member so that it can only be accessed any
class in the same package? -> Default.
5.class Sample4
{
void opt()
{
try{
int data=25/4;
System.out.println(data);
System.out.println("Rest of the code");
}
catch(ArithmeticException e){System.out.println(e);}
finally{System.out.println("Finally executed");}
}}
class Excep5
{
public static void main(String[]args)
{
Sample4 s1=new Sample4();
s1.opt();
System.out.println("OK");
}
}
Ans:- 6, Rest of the code,finally executed, OK.
6.Is it possible to store different parts of one java program(making an application in different packages)?
Ans:- No.
7.Predict the output:-
public abstract class Except implements
Runnable {
void Threading() { };
}
Ans:- The program will not complete because it does not implement the run() method.
8.Correct statement:-
Ans:- Thread run () method can also be called directly to create thread.
9.Select the correct statement which is not wrong:- A try block can be nested.
10.correct statement:-
Ans:- join method ensures all threads that started from main must end in order in which they started
and also main should end in last.