You are on page 1of 40

OOPS PROGRAMS

1. What is a class?

2. What is an object?

3. What is Method Overloading? Give examples.

4. What is method Overriding?

5. OOPs concept?

6. What is super class of the java?

7. How initialization of object and class will be done?

8. Explain about java and oops concept?

9. What is inheritence?

10. What is constructor?

11. What do you mean by casting?

12.Access Modifiers cannot be used for?


a)Local variables

1
OOPS PROGRAMS
b)static variables
c)non-static variables
d)Non of the above.

13About OOPs concept?

14Can we override static method?

15What is a constructor?

16Can we overload constructor?

17Which one is correct about an abstract class?

a)abstract class cannot implements interface.


b)abstract class may not have any abstract methods.
c)We can create object of an abstract class directly.
d)abstract class contains only abstract methods .

18Which of the below conditions to be satisfied for overloading to occur?

a)Both methods must have the same method name.


b)Both methods must have different argument list.
c)Both methods must have same argument list.

2
OOPS PROGRAMS
d)Both the methods have same/different return type
e)Both methods may have same/different access specifier

options:
a)a,b,d,e
b)c,d,e
c)b and d
d)c and d.

19.Which of the following statement/statements are true w.r.t static modifier?


a)Default values for static Variables are same as instance variable.
b)Cant overide static methods.
c)static blocks executes when class loads
d)During serilization,static fields like transient variables are not serilized.

20:Which one is the correct implementation syntax of following interface.


interface X{
public int getNumber()
}
a) X x 1=() ->100
b) X x 1=() ->return 100.
c) X x 1=(100) ->return 100
d) None of the above

3
OOPS PROGRAMS
21:which of the following statement interface method is used to delete the data?

a)executeUpdate()
b)execute()
c)executeQuery()
d)executedelete()

22:Which two statements are true about has-a and is-a relationship?
(choose two)

a)Inheritence represents an as-a relationship


b)Inheritence represents a has-a relationship
c)Interfaces must be used when creating a has-a relationship
d)Instance variable can be used when creating a has-a relationship.

23:Which is true about constructor?

a)constructor can not be overloaded


b)constructor can be final
c)constructor can be static
d)constructor can be private

24:Which statement is not true?

4
OOPS PROGRAMS
a)static method will not participate in inheritence
b)We can not overload static method
c)We can override is variable of a super class inside method class
d)We can assign child class object to the parent class object.

25:What wiil be output of the following pprogram


public class A{
int i=5;
public A(){
this(10);
System.out.println(i);
}
public A(int x){
this();
System.out.println(x);
}
public static void main(String[] args) {
A a1=new A()
}
}

26: public class Test{


public static void main(String[] args){
String[] array = new String[5];

5
OOPS PROGRAMS
Arrays.fill(array,"Hello");
System.out.println(array[i]);
}
}

a)e
b)null
c)Hello
d)ArrayindexOutOfBoundsException.

27:What is the output of the following code?


class Test{
public static void main(String[] args){
StringBuffer sb1 = new StringBuffer("Hello world");
StringBuffer sb2 = new StringBuffer("Hello World");
System.out.println(sb1==sb2);
System.out.println(sb1.equals(sb2));
}
}

a)false,false
b)false,true
c)true,false
d)true,true

6
OOPS PROGRAMS

28.Real world examples of oops?

29.What is a constructor?

30.What is method overriding?

31.What is method overloading?

32.What are keywords?

33.What ia an identifier?

34.What is class?

35.What is object?

36.What is inheritence.Explain with example other than father and son.

37.What is a class and object?

38.What is an interface?.Expalin?

7
OOPS PROGRAMS
39.What is public static void main(String[] args ) in java?

40.What is static keyword?

41.Explain briefly about polymorphism?

42.Explain briefly about Encapsulation?

43.Explain briefly about Abstraction?

44.What is multiple inheritence?

45.What do you mean by access modifiers?

46.What is type casting?

47.Difference between class and abstract class?

48.What is a constructor?

49.What is method overloading?.Syntax.

50.What is method overriding?.Syntax.

8
OOPS PROGRAMS
51.What is encapsulation?

52.What is inheritence?

53.Is java purely object oriented language or not?

54.Write a program on method Overloading.

55.OOPs concept and four pillars definition?

56.What is the use of interface?

57.Why inheritence is not possible in java explain with object class.

58.Explain inheritence?

59.About method overloading?

60.What is FIFO.Which follows FIFO?

61.What is pre-order,post-order,in-order?

62.Post-order?with example?

9
OOPS PROGRAMS
63.What is prefix,suffix with examples?

64.Why java an object oriented language?

65.What is constructor?

66.What is multiple inheritence?

67.What is constructor chaining?

68.What is run-time polymorphism?

69.What is function overriding?


88a)Early binding
b)late binding
c)pre-Mature binding
d)None of the above

70.What is constructor

71.What is java

72.What is oops concepts

10
OOPS PROGRAMS
73.What is object

74.What is class

75.What is abstract

76.What is inheritance

77.What is polymorphism

78.How many types of constructor

79.What is casting? How many types?

80.Method overloading

81.Method overriding

82.What is methos in java

83.Method binding

84.Abstraction

11
OOPS PROGRAMS
85.interface

86.Which inheritence is not supported by java?


a)multi level
b)multiple
c)single level

87.public class BaseC{


public static void main(String[] args)
Base bc=new BaseC();
bc.initial();
}
void initial()
int x=3;
int y=4;
System.out.println(" "+7+2+" ");
System.out.println(x+y);
System.out.println(" "+x+y+" ");
System.out.print(foo()+x+y+" ");
System.out.println(x+y+back());
}
String back()
return "back";
}

12
OOPS PROGRAMS
}

a)9 7 7 back 7 7 back


b)72 34 34 back34 34back
c)9 7 7 back34 34back
d)72 7 34 back34 7back

88.What is the o/p?


public class x{
final public int findResult(int p,int q){
return 9;
}
}
class Y extends X{
public int findResult(int p,int q){
return 10;
}
}
public class Test{
public static void main(String[] args)
y q = new y();

89.How many types of polymorphisms are supported by c++?


a)1 b)2 c)3 d)4

13
OOPS PROGRAMS

90.Late binding is implemented in c++?


a)Using c++tables
b)Using virtual tables
c)Using Indexed virtual tables
d)Using polymorphic tables

91.The mechanism that binds code and data together and keeps them secure from
outside world is known as
a)Abstraction
b)Encapsulation
c)Inheritence
d)Polymorphism

92.What is the o/p of the following


void func(int a,int b,int c)
{
printf("%d %d %d\n",a,b,c);
return 0;
}
int main()
{
int a=1,b=2,c=3;
func(a=b+c,a++,a=2);

14
OOPS PROGRAMS
return 0;
}
a)5 2 5
b)5 2 2
c)5 1 4
d)5 3 2

93.What is the size of empty class?


a)2 bytes b)1 byte c)4 bytes d)3 bytes

94.Abstraction

95.Interface

96.Inherotence

97.Encapsulation

98.Polymorphism.

99.What is a constructor.

100.Which of the following statements are incorrect?


a)static methods can call other static methods only.

15
OOPS PROGRAMS
b)static methods must only access static data.
c)static methods cannot refer to this or super in any way.
d)When object of class is declared,each object contains its own copy of static methods.

101.class Temp
{
private static int x=10;
private static int y=10;
private Temp()
{
this(9);
}
private Temp(int x)
{
this(x,y);
}
private Temp(int x,int y)
{
System.out.println(x*y);
}
public final static void main(String[] args)
{
Temp t = new Temp();
}

16
OOPS PROGRAMS
}

102.class HackerEarth
{
static void proc1()
{
System.out.println("Inside proc1");
throw new IllegalAccessException("java");
}
public static void main(String[] args)
{
proc1();
}
}

103.Which of the following ways to create an object of the sample class given below
and will work correctly?
class Sample
{
int i;
single j;
double k;
public sample(int ii,single jj,double kk)

17
OOPS PROGRAMS
{
i=ii;
j=jj;
k=kk;
}
}

a)Sample s1 = new Sample();


b)Sample s1 = new Sample(10);
c)Sample s2 = new Sample(10,1.2f);
d)Sample s3 = new Sample(10,1.2f,2.4);
e)Sample s1 = new Sample( ,2.5);

104.Explain single level inheritence.

105.Explain about polymorphism(real time examples)

106.Explain about inheritence(real time examples)

107.Difference between interface and Abstract.

108.Abstraction real time examples.

109.Expalin about stack and heap area.

18
OOPS PROGRAMS

110.Difference between method ovverriding and method overloading.

111.What is constructor.

112.What is inheritence.

113What is the difference between method and constructor?

114.Class and object

115.static and non-static

116.Object type casting

117.Program on upcasting.

118.Difference between c++ and java.

119.OOPs programs with real time and real world eg's.

120.What is encapsulation.

121.Why multiple inheritence is not possible.

19
OOPS PROGRAMS

122.Difference between abstract and interface.

123.Why java is not purely object oriented language

124.Real time examples of abstract class in java.

125.Oops concepts

126.Constructor variables

127.What in heritence

128. Variables namess

129.Inheritance and types of inheritance.

130.Type casting in java.

131.What is method overloading and method overriding.

132.Interface in java.

133.Uses of interface.

20
OOPS PROGRAMS

134.Write about inheritence.

135.What is oops

136.Programs on overridding and over loading.

137.What is polymorphism.

138.What is a constructor.

139.Why we use constructor.

140.Where we store static and non static methods.

141.What is a class

142.Where we use class

143.Why do we use class and object.What is the purpose?

144.OOPs concept.

145.Single level inheritence

21
OOPS PROGRAMS

146.public class Program{


int x=12;

public void method(int x){


x+=x;
System.out.println(x);
}
public static void main(String[] args)
{
Program t = new Program();
t.method(5);
System.out.println(t.x);
}
}

147.class Parent{
static void test(){
System.out.println("Parent");
}
}

public class Child extends Parent{


static void test(){

22
OOPS PROGRAMS
System.out.println("Child");
}
public static void main(String[] args){
Parent p= new Child();
p.test();
}
}

148.final classA
{
System.out.println("Hello World");
}
class B extends A
{
System.out.println("Have a great day");
}
class demo{
public static void main(String[] args)
{
B obj = new B();
}
}

149.public class Metti{

23
OOPS PROGRAMS
static Boolean b1[] = new Boolean(5);
public static void main(String args[]){
System.out.println(b[0]);
}
}

150.Difference between static and nonstatic.

151.OOPs concept in java.

152.What is inheritence.

153.Write a program in inheritence.

154.Write a program on Abstraction.

155.What is polymorphism and give one real time example?

156.Inheritance

157.Interface

158.Abstract

24
OOPS PROGRAMS
159.OOPs concept

160.Arrays

161.Collection basics.

162.Which class extends all enums.

163.Which of the following loops will execute the body of the loop.
even when the condition is initially false.

164.Which one doesnot support overloaded methods for +,-,*,/.

165.What will be the behaviour if constructor has return type.

166.What is the range of short data type.

167.Limitation of toString() for BigDecimal.

168.How JAVA is different from other languages.

169.How JAVA is object oriented languge.

170.Is Object is mandatory in OOPs.

25
OOPS PROGRAMS

171.Real time examples of abstraction,encapsulation.

172.What is Null pointer exception.

173.Tell about OOPs.

174.What is the difference oops in java and oops in python.

175.What is the difference between overloading and overriding.

176.What is oops

177.Call non static variables and non static methods.

178.Explain about OOPs pillars.

179.Explain about inheritence.

180.What is constructor,types of constructor

181.Outline features of java

182.what is abstract class

26
OOPS PROGRAMS

183.What do you about classes injava

184.What do you object in java

185.What is difference between local and global

186.What you mean by super keyword

187.What you know about String class.

188.What is typecasting with examples

189.What is final Keyword

190.What is the difference between the c and java.

191.What is the output of the following Java program?

class Derived
{
public void getDetails (String temp)
{
System.out.println("Derived class" +temp);

27
OOPS PROGRAMS
}
public class Test extends Derived
{
public int getDetails (String temp)
{
System.out.println("Test class" +temp);
return 0;
}
public static void main(String[] args)
{
Test obj - new Test ();
obj.getDetails ("GFG");
}
}
}
Options
A.Runtime error
B.Denved class GFG
C.Test class GFG
D.Compilation error
E.Derved class GFG Test class GFG

192.What is the output of the following Java program?


class Derived

28
OOPS PROGRAMS
{
public void getDetails()
{
System.out.printf("Derived class ");
}
}
public class Test extends Derived
{
public void getDetails()
{
System.out.printf("Test class ");
super.getDetails();
}
public static void main(String[] args)
{
Derived ob new Test();
obj.getDetails();
}
}
Options
A.Test class Derived class
B.Derived class Test class
C.Test class
D.Compilation error

29
OOPS PROGRAMS
E.Runtime effor

193.What is the output of the following Java program?


class Temp
{
private Temp (int data)
{
System.out.printf(" Constructor called ");
}
protected static Temp create(int data)
{
Temp obj new Temp(data);
return obj;
}
public void myMethod()
{
System.out.printf(" Meth called ");
}
public class Test
{
public static void main(String[] args)
Temp obj = Temp.create(20);
obj.myMethod();
}

30
OOPS PROGRAMS
}
Options
A.Compilation error
B.20
C.Constructor called
D.Method called
E.Constructor called Method called

194.What is the output of the following Java program?

class Helper
{
private int data;
private Helper()
{
data = 5;
}
}
public class Test
{
public static void main(String[] args)
{
Helper help - new Helper();
System.out.println(help.data);

31
OOPS PROGRAMS
}
Options
A.Compilation error-the constructor Helper()'not accessible
B.5
C.Compilation error- the private variable can not be assigned
D.Compilation error - the variable 'data' not accessible

195.What is the output of the following Java program?

class Main {
public static void main(String args[]) {
System.out.println(fun());

}
int fun()
{
return 20;
}
}
Options
A.20
B.Compile-time error
C.Run-time error
D.Some Garbage value will be printed

32
OOPS PROGRAMS

196.Which access specifier is usually used for data members of a class


a)protected
b)default
c)private
e)public

197.Which type of members cant be accessed in derived classes of a base class


a)All can be accesed
b)protected
c)private
d)public

198.Where is the memory allocated for the objects


a)catch
b)HDD
c)RAM
d)ROM

199.When is the object created with a new Keyword


a)At run time
b)At compile time
c)None
d)Depends on code

33
OOPS PROGRAMS
200.What is the number of parameters that a default constructor requires?
a)1
b)0
c)2
d)3

201.Data members and member functions of a class are private.default.True or False?


A)False
B)True
C)None
D)Depends on code

202.Under which pillar of OOPS do base class and derived class relationships come?
A)Polymorphism
B)Encapsulation
C)Inheritance
D)Abstraction

203.Which of the following can be inherited from the base class?


A)Constructor
B)Destructor
C)Static
D)None

34
OOPS PROGRAMS
204.Which among the following doesn't come under OOP concept?
a)Data hiding
b)Message Passing
c)Platform independent
d)Data binding

205.What is an abstraction in object-oriented programming?


a)Hiding the implementation and showing only the features
b)Hiding the important data
c)Hiding the implementation
d)Showing the important data

206.polymorphism, inheritance, abstract examples and code

207.Method OVERIDING program

208.Ooops concepts

209.polymorphism definition

210.Encapsulation definition

211.Inheritance definition

35
OOPS PROGRAMS
212.Local and global variable

213.Constructor

214.OOPs concept

215.Pillar of OOPs

216.Polymorphism

217.OOPs concept

218.What is public and privare?

219.Polymorphism

220.Encapsulation

221.Difference between java and core java

222.Polymorphism

223.Encapsulation

36
OOPS PROGRAMS
224.Abstraction

225.Inheritence

226.What is constructor Overloading?

227.What is an instance variable?

228.Java language has support for which of the following types of comment.
a)block,Line and javadoc.
b)javadoc,char and String.
c)single,multiple and quote.
d)javadoc,literal and string.

229.------------ is a mechanism for naming and visibility control of a class and its content.
a)None of the mentioned
b)Object
c)Packages
d)Interfaces

230.The java compiler


a)creates executable
b)produces java interpreter
c)creates classes

37
OOPS PROGRAMS
d)translates java source code to byte code.

231.Polymorphism

232.Encapsulation

233.About static and non-static.

234.class and object

235.What is java ?Explain it briefly.

236.What is inheritence?

237.Which is a valid keyword in java?

a)interface
b)String
c)float
d)unsigned

238.Where is the error in the following syntax?


class X
{

38
OOPS PROGRAMS
final void dispaly()
{
System.out.println("Hello");
}
}
class Y extends X
{
void display()
{
System.out.print("Welcome");
}
}

a)class extends
b)display
c)void display
d)System.out.println

239.The following syntax refers to


box b1 = new box();
box b2 = b1;

a)b2 object
b)new object

39
OOPS PROGRAMS
c)b1 object
d)same object
1.Difference between constructor overloading and method overloading.

240.Difference between abstraction and encapsulation

241.Multi-level inheritence.

242.Abstract class and interface

243.Encapsulation

40

You might also like