0% found this document useful (0 votes)
5 views

more mcq,programs

The document contains 50 multiple-choice questions (MCQs) related to programming concepts, particularly focusing on Object-Oriented Programming (OOP) in Java. It also includes four programming exercises that require writing Java code to solve specific problems, such as finding the highest and lowest numbers, checking for Superspy and Jolly numbers, and printing Pythagorean triplets. Each question and exercise is designed to test the understanding of Java programming and OOP principles.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

more mcq,programs

The document contains 50 multiple-choice questions (MCQs) related to programming concepts, particularly focusing on Object-Oriented Programming (OOP) in Java. It also includes four programming exercises that require writing Java code to solve specific problems, such as finding the highest and lowest numbers, checking for Superspy and Jolly numbers, and printing Pythagorean triplets. Each question and exercise is designed to test the understanding of Java programming and OOP principles.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

50 MCQ’s

1.Name the programming technique that implements programs as an organised collection of interactive objects.(a. Procedure
Oriented Programming b. Object Oriented Programming c. Modular Programming d. None of these)

2. Name the characteristics of Object Oriented Programming that hides the complexity and provides a simple interface.( a.
Encapsulation b. Abstraction c. Polymorphism d. Inheritance)

3. Which among the following operator is used to access individual members of an object?(a . (dot) b. – (minus) c. + (plus)d. /
(divide))

4. Which among the following modifier is generally used in a ‘class’?(a. public b.default c. Both a and b d. None of these)

5. Which among the following is a valid class name?(a. Simple Interest b. SimpleInterest c. 1SimpleInterest d. Simple@Interest)

6. Which among the following is a valid object name?(a. obj1 b. Obj 1 c. 1obj d. Obj#

7. Which among the following is a valid float literal?(a. 12.36f b. 12.36Fc. 12.36 d. Both a and b

8. Which among the following is a valid octal integer literal?(a. 0178 b. 675 Ans. c. 0675 d. OX675)

9. Which among the following is a valid method of initialising?(a. boolean f=true;b. boolean f=’true’; c. boolean f=True;d. None of
these

10. Which among the following is not a punctuator?(a. ; semicolon b. : colon c. . dot d., comma

11. Which among the following is not a primitive data type? a. int b. String c. float d. char

12. What is the largest possible value that can be stored in short data type? a. 215-1 b. 231-1 c. 27-1 d. 263-1.

13.If a is of type int and b is of type float what would be the resultant data type of a+b? a. int b. double c. float d. short

14.Which among the following is not a valid error in Java? a. Syntax errors b. Run-time errors c. Technical errors d. Logical errors

15. Which among the following Scanner methods allows us to input a number with a decimal point?a. nextInt() b. nextDecimal()
c.nextShort() d.nextFloat()

16. The output in BlueJ occurs in which window? a. Console window b. Terminal window c. Both a and b d.none

17. The input in BlueJ occurs in which window?a. Console window . b.Terminal window c.Both a and b d.none

18. Assigning value to a variable during declaration is called.(a. Declaration b. Initialisation c. Assignment d. None of these

19.Which among the following is used to represent single-line comment?a. // b. /* c.\\ d.<!—

20. Which among the following is a logical error?a. Missing semicolon b. Mismatched braces in classes and methods. c.
Misspelled keywords and identifiers. d. Addition is required but subtraction is performed.

21. Which among the following represents a syntax error?a. Dividing an integer by zero.b. Accessing an element that is out of
bounds of an array.c. Trying to store a value which is incompatible to a certain data-type.d. Missing semicolon

22. If the data that is to take part in a calculation in a method is fixed, which form of input is necessary?a. Initialisation b.
Parameterised input c.Scanner input d. None of these

21. In case you need to give a proper message (prompt string) before taking an input from the user, which would be the most
preferable method? a. Parameterised input b.initialisation c. Scanner input d.None of these

22. Which among the following is not a primitive data type?a. int b. String c. short d. Long
23. Name the operator that is used to allocate memory space for an object.a. Dot b.new c. Both a and b d. None of these

24. What is the name given to a memory location called in Java?a. Variable b. constant c.Data d.none

25. Which are the data types used in Java?a. Primitive data type b.composite data type c. Both a and b d. None of these

26. How are the characteristics of an object represented in a class?a. Data Members b. Access specifiers c. Member Functions d.
None of these

27. Which among the following is used to change the state of an object?a. Data Members b. Name of the class c. Both a and b d.
None of these

28. How is encapsulation implemented in a program?a. Using a class b.Using only functions c. Using only Variables d. None of
these

29. Information passed to a method through arguments is called _____.a. Message b. Numbers c. Variables d. Data

30. What among the following is not a component of a message?a. An object b. identifier c. Arguments d.Data Members

31. Which of the following is a composite data type?a. int b.String c. char d.float

32. Which of the following is not a wrapper class?a. Byte b. int c. Long d.Float

33. Wrapping up of data and method into a single unit is called ___.a. Encapsulation b.Abstraction c. Inheritance d.
Polymorphism

34. An OOP feature that allows all members of a class to be the members of another class.a. Encapsulation b.abstraction c.
Inheritance d.polymorphism

35. Which among the following best describes encapsulation?a. It is a way of combining various data members into a single unit
b. It is a way of combining various member functions into a single unit c. It is a way of combining various data members and
member functions into a single unit which can operate on any data d. It is a way of combining various data members and
member functions that operate on those data members into a single unit

36. Which feature can be implemented using encapsulation?a. Inheritance b. Abstraction c. Polymorphism d. Overloading

37.Multiple branching statement in java is-a.switch b.while c.for d.if else

38.Choose the odd one:- a.= b.! c.&& d.||

39.The number of bytes occupied by the constant true is- a.8 bytes b.1 byte c.1 bit d.16 bits

40.”Java compiled code (byte code) can run on all operating systems”-Name the feature a.robust and secure b.object oriented
c.platform independent d.multithreaded

41.The size of ‘\n’ is a.2 bytes b. 4 bytes c.8 bytes d.16 bytes

42.Identify the operator that gets the highest precedence while evaluating the given expression a+b%c*d-e; a.+ b- c.% d.*

43.To execute the loop 10 times, which of the following is correct? a.for(int i=11;i<=30;i+=2) b. for(int i=11;i<=30;i+=3)
c. for(int i=11;i<20;i++) d. for(int i=11;i<=21;i++)

44.The default value of boolean variable is a.False b.0 c.false d.True

45.The process of allocating memory space to an object- a.initialisation b.instantiation c.dynamic initialisation d.updation

46. Identify which of thte following leads to an infinite loop. a. for(i=10;i!=0;i--) b) for(i=3;i<=30;i+=3) c)
for(i=1;i>=1;i++) d) for(i=1;i>=0;i--)
47.An arithmetic expression which uses all it’s components of same data type is: a.equal b.real c.pure d.equivalent
48.The operator helps to connect method with an object and object with class.a= b.dot c.semi-colon d.colon

49.Keyword ‘new’ is used for _______ memory allocation.a.rotational memory allocation b.dynamic memory allocation c.false
memory allocation random memory allocation

50.Which of the following methods returns only an integer. a.Math.max() b.Math.ceil c.Math.round d.Math.sqrt

Q.1.WAP to input numbers till 0 is entered, from the numbers print highest and lowest, calculate LCM and HCF.
import java.util.*;
class lcmhcf
{public static void main()
{Scanner br=new Scanner(System.in);
int n,max,min,lcm=0,hcf;
System.out.println("Enter a number");
n=br.nextInt();
max=n;min=n;
while(n!=0)
{ System.out.println("Enter a number");
n=br.nextInt();
if(n>max)max=n;
if(n<min)min=n;
}int b=min;
System.out.println(max+" "+min);
while(true)
{if((min%min==0)&& (min%max==0))
{lcm=min; break;}++min;}
hcf=(max*b)/lcm;
System.out.println(lcm+" "+hcf);}}
Q.2.WAP to input a number check and print if it’s Superspy number.[sum of digits=count of digits,eg-102 3=3]
import java.util.*;
class superspy
{
public static void main()
{Scanner br=new Scanner(System.in);
int n,n1,d,s=0,c=0;
System.out.println("Enter a number");
n=br.nextInt();n1=n;
while(n!=0)
{d=n%10;
s=s+d;
c++;
n=n/10;
}
if(s==c)
System.out.println(n1+"Superspy");
else
System.out.println(n1+"Not Superspy");}
}
Q.3. WAP to print all Pythagorean triplets from 1 to 50.[a2+b2=c2]
class pythagorean
{
public static void main()
{int i;
for(i=1;i<=48;i++)
{
if(((i*i)+((i+1)*(i+1))==((i+2)*(i+2))
System.out.println(i+” “+i+1+” “+i+2);}}}
Q.4. WAP to input a number check and print if it’s a Jolly number or not.The number is said to be Jolly if it’s a four digit
number and sum of all digits=2X(Sum of first and last) For eg=1234 Sum of first and last=1+4=5 and sum of all
digits=1+2+3+4=10
import java.util.*;
class ushwa
{
public static void main()
{Scanner br=new Scanner(System.in);
int n,n1,n2,d,s=0,c=0,l=0,f=0;
System.out.println("Enter a number");
n=br.nextInt();n1=n;n2=n;
while(n!=0)
{d=n%10;
s=s+d;
c++;
n=n/10;
}
l=n1%10; f=n1/(int)Math.pow(10,c-1);
if(s==2*(l+f))
System.out.println(n2+"Jolly");
else
System.out.println(n1+"Not Jolly");}
}

You might also like