0% found this document useful (0 votes)
54 views1 page

Practice-Worksheet-4 Dry-Run (Func-Cons)

The document provides code snippets and questions related to Java programming concepts like classes, objects, methods, parameters, return types, etc. It includes code snippets demonstrating different Java concepts and questions testing understanding of concepts like instance variables, class variables, arguments, return types, etc.

Uploaded by

ziii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views1 page

Practice-Worksheet-4 Dry-Run (Func-Cons)

The document provides code snippets and questions related to Java programming concepts like classes, objects, methods, parameters, return types, etc. It includes code snippets demonstrating different Java concepts and questions testing understanding of concepts like instance variables, class variables, arguments, return types, etc.

Uploaded by

ziii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

a) Write dry-run and output:- b) Write dry-run and output:- c) Write dry-run and output:-

class Student{ class demo { public static void Write the prototypes for the
public static void main() { int n=10; String test(double d,int i) { following function descriptions
S="Cheese"; double ans = d+i; a. Function product() can be
Student S1=new Student(); S1.rollno=10; System.out.println(ans); } called only an object of the class
S1.name="Edward"; update(n , S , S1); public static void main() It takes a whole number and
System.out.print(n); System.out.print(S); { test(5.5 , 5); } } decimal number, it returns the
System.out.print(S1.rollno); product of the 2 numbers and
System.out.print(S1.name); } public static void can be used in any class.
update(int n, String S, Student S1) { n=20; b. Function encrypt() takes a
S="Butter"; S1.rollno=20; S1.name="Bella"; }} string and a number and returns
a string, this function can be
used only in the same class. It
can be called with the class
name.
d) e)Write the prototype of a f)class sample{int a,b;static int c;
In the code given below, Identify Actual function search which takes sample(int a1,int b1)
parameters, Formal parameters, Prototype, two arguments a String and a {a=a1;b=b1;}
Signature, Return type. Define each of them. character and returns an void compute(){int
class coffee{ public static void main() { int N =10; integer value. result;result=a+b;
String S = compare( N,100); System.out.println(S); } System.out.println(result);}
public static String compare(int S, int S1) public static void main()
{ if (S>S1) return “White”; else return “Red”; } } {sample ob=new
sample(5,8);ob.compute();}}
a)Name the instance variables
and its value
b)Name the class variable
c)Name the argument/method
variable
d)Name the local variable
g) Write dry-run and output:- h) Write dry-run and output:- i) Write dry-run and output:-
class box{ class Myclass class sum
int width,height,length,volume; {static int x=7;int y=2; {private int x,y;
void volume(int height,int length,int width) void sampleMethod(int n) public int total;
{volume=width*height*length;} {System.out.println(n); sum(int a,int b)
public static void main() System.out.println(y);} {x=a;y=b; total=x+y;}
{box obj=new box(); public static void main() public static void main()
obj.volume(3,2,1);System.out.println(obj.volume);}} {Myclass obj=new Myclass(); {sum tot=new sum(50,46);
System.out.println(x); System.out.print(tot.total);}}
Obj.sampleMethod(5);
int a=6;
System.out.println(a);}

j)public void show(String s)


{if(s.length()>10)
System.out.println(s.substring(11,s.length()));
else
System.out.println(S.toLowerCase());}
a)If the input to the function is: “This is a Program”
b)If the input to the function is CAPTAIN

PRACTICE WORKSHEET-4

You might also like