Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

JAVA Programming :: Inheritance

Home > JAVA Programming > Inheritance > General Questions

1. Which of the following is a technique for hiding the internal implementation details of an object?

Answer: Encapsulation

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

2. In an Object Oriented system, if class A inherits its properties from class B, class A and B are known as _______________ and ___________ class respectively.

Answer: Sub and Super

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

3. What all gets printed when the following program is compiled and run.

public class test {
public static void main(String args[]) {
inti, j=1;
i = (j>1)?2:1;
switch(i) {
case 0: System.out.println(0); break;
case 1: System.out.println(1);
case 2: System.out.println(2); break;
case 3: System.out.println(3); break;
}
}
}

Answer: Both B & C

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

4. What is the output for the below code?

import javutil.Iterator;
import javutil.TreeSet;
public class Test {
public static void main(String... args) {
TreeSet s1 = new TreeSet();
s1.add("one");
s1.add("two");
s1.add("three");
s1.add("one");
Iterator it = s1.iterator();
while (it.hasNext() ) {
System.out.print( it.next() + " " );
}
}
}

Answer: one three two

Explanation:

TreeSet assures no duplicate entries.it will return elements in natural order, which, for Strings means alphabetical.

Workspace

Tags:

No Tags on this question yet!

5. What is the output for the below code ?

interface A {
public void printValue();
}
public class Test{
public static void main (String[] args){
A a1 = new A() {
public void printValue(){
System.out.println("A");
}
};
a1.printValue();
}
}

Answer: A

Explanation:

The A a1 reference variable refers not to an instance of interface A, but to an instance of an anonymous (unnamed) class. So no compilation error.

Workspace

Tags:

No Tags on this question yet!

6. What will be the result of compiling and run the following code:

public class Test {
public static void main(String... args) throws Exception {
File file = new File("test.txt");
System.out.println(file.exists());
file.createNewFile();
System.out.println(file.exists());
}
}

Answer: false true

Explanation:

creating a new instance of the class File, you're not yet making an actual file, you're just creating a filename. So file.exists() return false. createNewFile() method created an actual
file.so file.exists() return true.

Workspace

Tags:

No Tags on this question yet!

7. What is the output for the below code ?

1. public interface InfA {
2. protected String getName();
3. }
4. public class Test implements InfA{
5. public String getName(){
6. return "test-name";
7. }
8. public static void main (String[] args){
9. Test t = new Test();
10. System.out.println(t.getName());
11. }
12. }

Answer: Compilation fails due to an error on lines 2

Explanation:

Illegal modifier for the interface method InfgetName(); only public and abstract are permitted

Workspace

Tags:

No Tags on this question yet!

8. What will be the result of compiling the following code:

public class SuperClass {
public int doIt(String str, Integer... datthrows Exception{
String signature = "(String, Integer[])";
System.out.println(str + " " + signature);
return 1;
}
}
public class SubClass extends SuperClass{
public int doIt(String str, Integer... dat
{
String signature = "(String, Integer[])";
System.out.println("Overridden: " + str + " " +
signature);
return 0;
}
public static void main(String... args)
{
SuperClass sb = new SubClass();
sb.doIt("hello", ;
}
}

Answer: Complilation fails

Explanation:

Unhandled exception type Exception.

Workspace

Tags:

No Tags on this question yet!

9. What is the output for the below code ?

1. public class A {
2. public void printName(){
3. System.out.println("Value-A");
4. }
5. }
6. public class B extends A{
7. public void printName(){
8. System.out.println("Name-B");
9. }
10. }
11. public class C extends A{
12. public void printName(){
13. System.out.println("Name-C");
14. }
15. }
16. public class Test{
18. public static void main (String[] args) {
19. B b = new B();
20. C c = new C();
21. b = c;
22. newPrint(b);
23. }
24. public static void newPrint(A {
25. printName();
26. }
27. }

Answer: Compilation fails due to an error on lines 5

Explanation:

Reference variable can refer to any object of the same type as the declared reference OR can refer to any subtype of the declared type. Reference variable "b" is type of class B
and reference variable "c" is a type of class So Compilation fails.

Workspace

Tags:

No Tags on this question yet!