0

Error

Class Student { int roll; int getroll(int x) { roll=x; } void putroll() { System.out.println("ROLL NUMBER IS ENTERED BY THE USER IS"+roll); } } Class Test extends Student { int getmarks(int a,int b, int c,int d,int e) { int java,python,nodejs,android,ds; java=a; python=b; nodejs=c; android=d; ds=e; } int putmarks() { System.out.println("Test 1 marks is"+java); System.out.println("Test 2 marks is"+python); System.out.println("Test 3 marks is "+nodejs); System.out.println("Test 4 marks is "+android); System.out.println("Test 5 marks is"+ds); } } Class Result extends Test { int display { putroll(); putmarks(); int total=java+python+nodejs+android+ds; System.out.println(total); } } Class Main { public Static void main (String arg[]) { Result obj=new Result(); obj.getroll(1); obj.getmarks(100,200,300,400,500); obj.diplay(); } }

26th Jul 2022, 4:15 AM
Abhishek
Abhishek - avatar
6 Antworten
0
abhishek bairwa error what? Always explain your question Always make code in Code Playground and share the link with question. Class should be class Your method should return something if you use return type except void which doesn't return anything. So int getmarks() should be void getmarks() because this method is not returning anything. Declare variables outside the method getmarks(); https://code.sololearn.com/csNb7PFV9ZLJ/?ref=app
26th Jul 2022, 5:48 AM
A͢J
A͢J - avatar
0
This kaise kaam karta hai
26th Jul 2022, 6:02 AM
Abhishek
Abhishek - avatar
0
abhishek bairwa this refers current object in a method or constructor. this can be used to access current class method or constructor this returns current class object. this mainly used to remove the confusion between class attributes and parameters. See this example: int java, python, nodejs, android, ds; void putMarks(int java, int python, int nodejs, int android, int ds) { this.java = java; this.python = python; this.nodejs = nodejs; this.android = android; this.ds = ds; } here class attribute is 'java' and parameter is also 'java' so if we write only this: java = java; Then we will get '0' so to get actual value we have to use 'this' like: this.java = java; Here this.java will refer to class attributes and 'java' is a method parameters. In your code method parameters name are different so that will work without 'this' also
26th Jul 2022, 6:14 AM
A͢J
A͢J - avatar
0
I want to ask one thing that class ke attribute ko mai yaha par variable bol sakta hu
26th Jul 2022, 7:04 AM
Abhishek
Abhishek - avatar
0
abhishek bairwa Yes attributes ka matlab variable
26th Jul 2022, 7:36 AM
A͢J
A͢J - avatar
0
names of methods getroll(), getmarks() are little confused because they only set attributes Common names for this type of methods are setRoll(), setMarks()
26th Jul 2022, 9:05 AM
zemiak